I'm looking to remove the '/' from the end of a variable so I can check if a file is a symlink to a directory. I've tried just about every method I could think of or find online, is there something I'm missing?
If I check if a file is a symlink with the '/' on the end, it treats it as a directory. This can be checked by running:
if [ -L symtest/ ] ; then echo "symlink"; fi
where symtest is a symlink to a directory. The above outputs nothing.
When I remove the '/', it works fine and outputs "symlink":
if [ -L symtest ] ; then echo "symlink"; fi
My question is, is there a way to remove the '/' from the name when it's passed as a variable to a function?
The function would look something like:
function is_it_a_symlink() {
if [ -L $1 ] ; then
echo "This file is a symlink!"
else
echo "This file is not a symlink!"
fi
}
Thanks in advance.
functionkeyword -- which breaks compatibility with POSIX sh but adds no value over the standardized function declaration syntax -- is onesuch).directorys=$@loses boundary information -- one can't distinguish between./yourscript "foo bar" "baz qux"and./yourscript foo bar baz quxafter using it; thelinkchkfunction is missing quotes (needs to be"$1"/*andlinkchk "$element"), and more.testoperators is wiki.bash-hackers.org/commands/classictest; another reliable resource is the Wooledge wiki, ie. mywiki.wooledge.org/BashGuide/TestsAndConditionals. There's also the POSIX specification fortestat pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html