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
How about using readlink?
# if symlink, readlink returns not empty string (the symlink target)
# if string is not empty, test exits w/ 0 (normal)
#
# if non symlink, readlink returns empty string
# if string is empty, test exits w/ 1 (error)
simlink? () {
test "$(readlink "${1}")";
}
FILE=/usr/mda
if simlink? "${FILE}"; then
echo $FILE is a symlink
else
echo $FILE is not a symlink
fi