feature request: commands to easily manipulate $PATH

Bug #619010 reported by Lesmana Zimmer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: bash

adding directories to $PATH is a very common task. it is desirable to only add a directory to $PATH if it is not already there. sadly that is quite hard to do. removing directories from $PATH is not as common but at least as hard.

i think bash should have commands to add directories uniquely to $PATH and remove from $PATH

for example:
path_append () { path_remove $1; export PATH="$PATH:$1"; }
path_prepend () { path_remove $1; export PATH="$1:$PATH"; }
path_remove () { export PATH=`echo -n $PATH | awk -v RS=: -v ORS=: '$0 != "'$1'"' | sed 's/:$//'`; }

from http://stackoverflow.com/questions/370047/what-is-the-most-elegant-way-to-remove-a-path-from-the-path-variable-in-bash

it would be better if the commands do not depend on anything outside of bash

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.