shell - test -h 和 test -L 的区别

标签 shell testing ksh symlink

ksh shell 中 test -L filenametest -h filename 有什么区别。从手册页来看,两者都用于标识符号链接(symbolic link),但我想知道确切的区别。

这是手册页中的描述。

 -h file                 True if file exists and  is  a  sym-
                         bolic link.
 -L file                 True if file exists and  is  a  sym-
                         bolic link.

最佳答案

ksh93 的源代码,在文件 bltins/test.c 中,表明这两个选项的处理方式完全相同,除了作者对 future 的希望:

        case 'L':
        case 'h': /* undocumented, and hopefully will disappear */
            if(*arg==0 || arg[strlen(arg)-1]=='/' || lstat(arg,&statb)<0)
                    return(0);
            return(S_ISLNK(statb.st_mode));

由此我得出结论,它们的行为完全相同,但是 -h 是一个遗留选项,可能有一天会消失:-)

关于shell - test -h 和 test -L 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1997666/

相关文章:

shell - Go 获取一个目录名作为参数

ksh - 输出文件描述符重定向

linux - 将函数命名为环境命令

shell - 无法使用 ffmpeg 将评论元数据提供给 MP3 文件

linux - Bash while 循环使用包含本地 $variable 的远程 grep

android - INSTRUMENTATION_RESULT : shortMsg=java. lang.NoClassDefFoundError 运行 Android Instrumentation 测试

python - 在测试中覆盖 Django 缓存设置

ios - 如何在不导航所有层次结构的情况下测试我的应用程序中的特定屏幕

shell - 我可以获取 KornShell 中当前脚本的绝对路径吗?

linux - 如何在 bash 脚本中的 select 语句中调用脚本