diff --git a/share/fish.in b/share/fish.in index 9418cbcf8..816771b3f 100644 --- a/share/fish.in +++ b/share/fish.in @@ -40,12 +40,14 @@ if test "$USER" = root set path_list $path_list /sbin /usr/sbin /usr/local/sbin end -for i in $path_list - set -l regex "^$i\(\|/*\)\$" - if not printf "%s\n" $PATH|grep $regex >/dev/null - if test -d $i - set PATH $PATH $i - end +# Make a regular expressin that matches any component in the PATH. A +# trailing slash is ok. The sed call is to remove the last '\|'. + +set -l path_regexp \\\((printf "^%s\\(\\|/\\)\$\\|" $PATH | sed -e "s/..\$//")\\\) + +for i in (printf "%s\n" $path_list|grep -v $path_regexp) + if test -d $i + set PATH $PATH $i end end