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
Linux bash脚本将字符串视为命令_Linux_Bash_Shell_Centos - Fatal编程技术网

Linux bash脚本将字符串视为命令

Linux bash脚本将字符串视为命令,linux,bash,shell,centos,Linux,Bash,Shell,Centos,我对bash脚本有一个noobish问题。 它将字符串视为命令 剧本是 #!/bin/bash if ["$(pidof whatever)"] then echo "suicide" fi exit 0 我在运行时遇到的错误是“[29999]未找到命令” 感谢您的帮助和时间。您需要在[和]之间留出空间 e、 g 或 在[和$之间需要一个空格[是测试命令 #!/bin/bash if [ $(pidof whatever) ] then echo "suicide"

我对bash脚本有一个noobish问题。 它将字符串视为命令

剧本是

 #!/bin/bash
 if ["$(pidof whatever)"]
 then
  echo "suicide"
 fi
 exit 0
我在运行时遇到的错误是“[29999]未找到命令”


感谢您的帮助和时间。

您需要在[和]之间留出空间 e、 g


[
$
之间需要一个空格
[
是测试命令

 #!/bin/bash
 if [ $(pidof whatever) ]
 then
  echo "suicide"
 fi
 exit 0

问题似乎是测试操作员之间缺少空间。请尝试:

 #!/bin/bash
 if [ "$(pidof whatever)" ]
 then
  echo "suicide"
 fi
 exit 0

希望这有帮助!

[
是一个命令。与其他任何命令一样,
bash
希望命令后面有空格,然后是第一个参数,然后是另一个空格,等等。下面是正确的方法:

if [ "$(pidof whatever)" ]; then ...

导致错误消息的是方括号周围的空格,而不是引号。
 #!/bin/bash
 if [ "$(pidof whatever)" ]
 then
  echo "suicide"
 fi
 exit 0
if [ "$(pidof whatever)" ]; then ...