With /bin/bash
, how would I detect if a user has a specific directory in their $PATH variable?
For example
if [ -p \"$HOME/bin\" ]; then
There is absolutely no need to use external utilities like grep
for this. Here is what I have been using, which should be portable back to even legacy versions of the Bourne shell.
case :$PATH: # notice colons around the value
in *:$HOME/bin:*) ;; # do nothing, it's there
*) echo "$HOME/bin not in $PATH" >&2;;
esac