if [ -L ${my_link} ] ; then
if [ -e ${my_link} ] ; then
echo "Good link"
else
echo "Broken link"
fi
elif [ -e ${my_link} ] ; then
echo "Not a link"
else
echo "Missing"
fi
# 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
mda="/usr/mda"
if [ ! -L "${mda}" ]; then
echo "=> File doesn't exist"
fi
if you want to do it in more advanced style you can write it like below:
#!/bin/bash
mda="$1"
if [ -e "$1" ]; then
if [ ! -L "$1" ]
then
echo "you entry is not symlink"
else
echo "your entry is symlink"
fi
else
echo "=> File doesn't exist"
fi
the result of above is like:
root@linux:~# ./sym.sh /etc/passwd
you entry is not symlink
root@linux:~# ./sym.sh /usr/mda
your entry is symlink
root@linux:~# ./sym.sh
=> File doesn't exist