bash – 如何检查符号链接是否存在

我正在尝试检查bash中是否存在符号链接。这是我尝试过的。
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

但是,这不起作用。
如果’!’被遗漏,它永远不会触发。而如果 ‘!’在那里,它每次都会触发。

如果“文件”存在并且是符号链接(链接文件可能存在或可能不存在),则-L返回true。你想要-f(如果文件存在并且是常规文件则返回true)或者只是-e(如果文件存在而不管类型如何都返回true)。

根据GNU manpage,-h与-L相同,但根据BSD manpage,不应使用:

-h file True if file exists and is a symbolic link. This operator is retained for compatibility with prevIoUs versions of this program. Do not rely on its existence; use -L instead.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...