Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash unix shell条件下的-w运算符是什么?_Bash_Unix_If Statement_Sh - Fatal编程技术网

Bash unix shell条件下的-w运算符是什么?

Bash unix shell条件下的-w运算符是什么?,bash,unix,if-statement,sh,Bash,Unix,If Statement,Sh,它似乎起到了一种作用 反转… 例如: 返回“失败” 但我不确定,因为 #!/bin/bash set -x #a=1 #b=2 if [ "$a" -o -w "$b" ]; then echo "ok" else echo "fail" fi 还返回“fail”。如果更换-w on!这将返回“ok” 请告诉我这个操作员在哪里。Bash和sh手册只包含-a和-o运算符。它测试文件是否存在并且可写。阅读test命令的手册。它测试文件是否存在且可写。阅读test命令的手册。

它似乎起到了一种作用 反转…
例如:

返回“失败”

但我不确定,因为

#!/bin/bash
set -x
#a=1
#b=2
 if [ "$a"  -o -w  "$b" ]; then
   echo "ok"
 else 
   echo "fail"
 fi
还返回“fail”。如果更换-w on!这将返回“ok”


请告诉我这个操作员在哪里。Bash和sh手册只包含-a和-o运算符。

它测试文件是否存在并且可写。阅读
test
命令的手册。

它测试文件是否存在且可写。阅读
test
命令的手册。

这在
manbash
中有记录,相同的摘录可通过
帮助测试获得:

  -w FILE        True if the file is writable by you.

这在
manbash
中有记录,相同的摘录可通过
help test
获得:

  -w FILE        True if the file is writable by you.

只是一些附加信息:

[ -e file ] : if "file" exists
[ -f file ] : if "file" exists and it is a file
[ -s file ] : if "file" exists and it is not empty
[ -d file ] : to check if "file" exists and it is a directory
[ -r file ] : if "file" exists and readable
[ -w file ] : if "file" exists and writable
[ -x file ] : if "file" exists and it is executable
[ -O file ] : if "file" exists and it is owned by current user
[ -G file ] : if "file" exists and default group same as the current user
[ file_1 -nt file_2 ] : if "file_1" newer than "file_2"
[ file_1 -ot file_2 ] : if "file_1" older than "file_2"

只是一些附加信息:

[ -e file ] : if "file" exists
[ -f file ] : if "file" exists and it is a file
[ -s file ] : if "file" exists and it is not empty
[ -d file ] : to check if "file" exists and it is a directory
[ -r file ] : if "file" exists and readable
[ -w file ] : if "file" exists and writable
[ -x file ] : if "file" exists and it is executable
[ -O file ] : if "file" exists and it is owned by current user
[ -G file ] : if "file" exists and default group same as the current user
[ file_1 -nt file_2 ] : if "file_1" newer than "file_2"
[ file_1 -ot file_2 ] : if "file_1" older than "file_2"

因为
[
实际上是一个命令,几乎与
test
命令相同(区别在于
[
需要
]
作为其最后一个参数)。
test
[
当然是同一个命令,它们实际上是同一个二进制文件上的两个链接。谢谢。我知道-w文件,但我不知道可以从变量中应用数值。通过strace,我知道它是如何工作的。@Jean BaptisteYunès
test
[
都是
bash
shell内置。文档在
manbash
中。通常,系统也有一个
test
可执行文件,可以作为
/usr/bin/test
访问。是可执行文件,而不是bash内置文件,由
mantest
@Jean BaptisteYunès记录:即使它们是同一个执行文件表中,它们的行为略有不同。
test-f filename]
是一个错误。因为
[
实际上是一个命令,几乎与
test
命令相同(区别在于
[
需要
]
作为其最后一个参数)。
test
[
当然是同一个命令,它们实际上是同一个二进制文件上的两个链接。谢谢。我知道-w文件,但我不知道可以从变量中应用数值。通过strace,我知道它是如何工作的。@Jean BaptisteYunès
test
[
都是
bash
shell内置。文档在
manbash
中。通常,系统也有一个
test
可执行文件,可以作为
/usr/bin/test
访问。是可执行文件,而不是bash内置文件,由
mantest
@Jean BaptisteYunès记录:即使它们是同一个执行文件表中,它们的行为略有不同。
test-f filename]
是一个错误。
test
bash
手册页条目只按名称提到了
-a
-o
,但它确实让您参考了关于条件表达式的部分,其中记录了其他原语。顺便说一句,
-a
-o
被认为是过时的;您应该使用
[“$a”]| |[-w“$b']
取而代之。
bash
测试的手册页条目
只按名称提到了
-a
-o
,但它确实让您参考了关于条件表达式的部分,其中记录了其他原色。顺便说一句,
-a
-o
被认为是过时的;您应该使用
[“$a”]|【-w“$b']