我正在尝试检查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.
原文地址:https://www.jb51.cc/bash/387310.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。