Linux bash脚本将字符串视为命令
我对bash脚本有一个noobish问题。 它将字符串视为命令 剧本是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"
#!/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 ...