shell - 检查文件是否是 Linux 上的链接

标签 shell unix scripting ksh symlink

我正在尝试使用 -h filename 命令检查 KornShell (ksh) 脚本中是否存在符号链接(symbolic link)。这在 HP 盒子上效果很好。

不确定 Linux、AIX 和 Solaris 机器的正确选项是什么。

对此有什么见解吗?

最佳答案

-hPOSIX spec 的一部分;它应该在任何模糊合理的地方都有效。

根据 Mac OS X 上的man test:

     -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

关于shell - 检查文件是否是 Linux 上的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/706421/

相关文章:

linux - Shell 脚本错误处理

shell - 使用 wget 下载文件时如何仅使用文件名保存文件

java - 使用 JSch 打开 SSH channel 时出现 "session is down"错误

linux - 暂停具有打开菜单的应用程序会卡住 unix 桌面

bash - 在 shell 中用逗号替换新行

bash - 如何处理 bash 中的每个第二个文件?

gitlab-shell : Disallowed command

linux - 为什么这个 bash 代码不起作用?

macos - 苹果电脑 : Lack of --printf for stat

Java 日志记录和 Unix Nohup 问题