Check If Shell Script $1 Is Absolute Or Relative Path [duplicate]

[ ... ] doesn’t do pattern matching. /* is being expanded to the contents of /, so effectively you have

if [ "$DIR" = /bin /boot /dev /etc /home /lib /media ... /usr /var ]

or something similar. Use [[ ... ]] instead.

if [[ "$DIR" = /* ]]; then

For POSIX compliance, or if you just don’t have a [[ that does pattern matching, use a case statement.

case $DIR in
  /*) echo "absolute path" ;;
  *) echo "something else" ;;
esac

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)