Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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 与grep在if上的争论太多_Bash_Shell_Grep - Fatal编程技术网

Bash 与grep在if上的争论太多

Bash 与grep在if上的争论太多,bash,shell,grep,Bash,Shell,Grep,我试图在我的文件中查找$allowtunnel字符串 基于: 现在我的脚本中有以下内容: allowtunnel="PermitTunnel" if [ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]; then 因为在执行时它说“太多的参数”,所以我在查看时发现: 所以我把它改成: if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then 但现在,它给了我下一个: ./script_i

我试图在我的文件中查找
$allowtunnel
字符串

基于:

现在我的脚本中有以下内容:

allowtunnel="PermitTunnel"
if [ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]; then
因为在执行时它说“太多的参数”,所以我在查看时发现:

所以我把它改成:

if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then
但现在,它给了我下一个:

./script_install.sh: línea 242: se esperaba un operador binario condicional
./script_install.sh: línea 242: error sintáctico cerca de `-Fxq`
./script_install.sh: línea 242: `    if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then`
翻译如下:

./script_install.sh: line 242: binary conditional operator was expected
./script_install.sh: line 242: syntax error near of `-Fxq`
./script_install.sh: line 242: `    if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then`
据我所知,它不允许我使用第二个
[]
,因为它需要另一个操作符。这让我不知道该怎么办

我也看过这张:,但因为我不是在比较什么,而是在等待grep的结果,所以我从这张照片中得到了任何有用的东西


感谢阅读

,因为grep根据是否找到记录返回退出状态,您可以编写if语句,如:

if grep .....; then

阅读手册,
[]
[[]]
的用途完全不同;它们本身就是命令。我会修改切普纳的评论,删除“just”<代码>[不是shell语法的一部分(但是
[[
是)。