【发布时间】:2018-09-08 18:33:43
【问题描述】:
#!/bin/sh
read name
if test "$name"=akash
then
echo "Hello how are you"
else
echo "sorry"
这是我的脚本,但在这两种情况下,我都会收到“你好,你好吗”的回复
【问题讨论】:
-
看起来像 Cargo-cult 编程,感谢阅读文档常见问题解答:mywiki.wooledge.org/BashFAQ |导游:mywiki.wooledge.org/BashGuide |参考:gnu.org/s/bash/manual | wiki.bash-hackers.org | mywiki.wooledge.org/Quotes |检查您的脚本:shellcheck.net
-
test "$name" = akash-- 空格很重要。 -
以
if结尾并正确缩进代码可能不是最糟糕的。缩进就像是对读者表现出一点尊重,值得清晰/可读……
标签: linux shell if-statement scripting