Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The compact one-liners below are similar but avoid adding duplicate items to PATH, so are fine to call in various init scripts.

In Bash:

  path_append() { local p; for p; do [[ :"$PATH": =~ :"$p": ]] || PATH+=:$p; done; }
  path_prepend() { local p; for p; do [[ :"$PATH": =~ :"$p": ]] || PATH=$p:$PATH; done; }
In portable POSIX shell:

  path_append() { for p; do case :"$PATH": in *:"$p":*) ;; *) export PATH="$PATH:$p" ;; esac; done; }
  path_prepend() { for p; do case :"$PATH": in *:"$p":*) ;; *) export PATH="$p:$PATH" ;; esac; done; }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: