在我的一个 shell 脚本中,我看到
if [[ ! -d directory1 || ! -L directory ]] ; then
-d和-L选项在这里是什么意思?我在哪里可以找到有关在某种if情况下使用的选项的信息?
您可以这样做,这将显示该命令help test接受的大多数选项。[[
您也可以这样做help [,这将显示其他信息。您可以help [[获取有关该类型条件的信息。
另请参阅man bash“条件表达式”部分。
bash具有命令的内置帮助help。您可以使用以下命令轻松找到内置 bash 的选项help:
$ help [[
...
Expressions are composed of the same primaries used by the `test' builtin
...
$ help test
test: test [expr]
Evaluate conditional expression.
...
[the answer you want]
检查给-d定目录是否存在。对符号链接的 -L测试。
Advanced Bash-Scripting Guide中的文件测试运算符解释了各种选项。这是bash 的手册页,也可以通过在终端中键入来找到。man bash
在 Bourne shell 中,[并被test链接到相同的可执行文件。因此,您可以在测试手册页中找到许多可用的各种测试。
这个:
if [[ ! -d directory1 || ! -L directory ]] ; then
是说如果不是directory1目录或directory不是链接。
我相信正确的语法应该是:
if [[ ! -d $directory1 ] || [ ! -L $directory ]] ; then
或者
if [[ ! -d $directory1 -o ! -L $directory ]] ; then
您的 OP 中的行是否正确?