如果file是LINUX OS上的链接

kad*_*hpa 3 unix shell scripting symlink ksh

我试图使用"-h filename"命令检查KornShell(ksh)脚本中是否存在符号链接.这适用于HP机箱.

不确定Linux,AIX和Solaris机箱的正确选项是什么.

对此有何见解?

Bri*_*ell 6

-hPOSIX规范的一部分; 它应该适用于任何模糊合理的地方.

根据man testMac OS X:

     -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.

-L也是标准化的,所以如果你发现任何-h不起作用的地方,你应该尝试-L.


wha*_*ley 5

至少在Linux系统上是-h(bash是我的shell):

lrwxrwxrwx 1 mule mule 37 Feb 27 09:43 mule.log -> /home/mule/runtime/mule/logs/mule.log
[mule@emdlcis01 ~]$ if [[ -h mule.log ]]; then echo "mule.log is a symlink that exists" ; fi
mule.log is a symlink that exists
Run Code Online (Sandbox Code Playgroud)

检查man test您可以在给定环境中使用的文件和字符串上可用的运算符.