2 # avoiding bashisms so it can be used in edge cases where I don't have bash,
3 # however, I'm not super confident that I've avoided them all
7 local help="usage: path_add [options] PATH
9 --end: adds to end of path, which will give it lowest priority
10 --ifexists: add to path only if the directory exists"
11 local found x y z ifexists end loop newpath
15 # portable substring matching is ugly http://mywiki.wooledge.org/BashFAQ/041
19 if [ "$1" = --end ]; then
21 elif [ "$1" = --ifexists ]; then
23 elif [ "$1" = --help ]; then
35 # build up the path without the components we want to add
38 if [ "$x" = "$y" ]; then
45 if [ ! "$newpath" ]; then
56 if ! $ifexists ||
[ -d "$x" ]; then
57 if [ ! "$PATH" ]; then