How to check if a symlink exists

I’m trying to check if a symlink exists in bash. Here’s what I’ve tried.

mda=/usr/mda
if [ ! -L $mda ]; then
  echo "=> File doesn't exist"
fi


mda="/usr/mda"
if [ ! -L $mda ]; then
  echo "=> File doesn't exist"
fi

However, that doesn’t work.
If ‘!’ is left out, it never triggers. And if ‘!’ is there, it triggers every time.

8 Answers
8

Leave a Comment