所以我想根据主机设置不同的路径,但不幸的是它不工作。这是我的脚本:
if [$HOSTNAME == "foo"]; then echo "success" else echo "failure" fi
这是怎么回事?
-bash: [foo: command not found failure
我知道$ HOSTNAME是foo,所以我不知道是什么问题。我相当新的bash。任何帮助将不胜感激!谢谢!
用于比较shell中的字符串的POSIX和便携式方法是
原文链接:https://www.f2er.com/bash/387979.htmlif [ "$HOSTNAME" = foo ]; then printf '%s\n' "on the right host" else printf '%s\n' "uh-oh,not on foo" fi
虽然案例陈述可能更灵活:
case $HOSTNAME in (foo) echo "Woohoo,we're on foo!";; (bar) echo "Oops,bar? Are you kidding?";; (*) echo "How did I get in the middle of nowhere?";; esac