我正在编写一个需要区分常规文件和符号链接的 bash 脚本。我以为我可以用 if/test 表达式来做到这一点,但它不像我预期的那样工作:
$ touch regular_file
$ test -f regular_file; echo $?
0
$ test -h regular_file; echo $?
1
$ ln -s regular_file symlink
$ test -h symlink; echo $?
0
$ test -f symlink; echo $?
0
Run Code Online (Sandbox Code Playgroud)
这是为什么?而且,我怎样才能正确地做到这一点?
bash ×1