【发布时间】:2014-09-12 05:33:36
【问题描述】:
我正在开发模式下运行 Chrome 操作系统,并且正在创建一个 bash 文件。代码如下所示:
echo -n "Username: "
read username: "
if [ $username == "mycroft" ]; then
echo "Correct!"
fi
我的问题是,当我用/bin/sh ./login.sh 运行crosh 中的代码时,我输入
在mycroft,我得到这个错误:
[: 4: mycroft: unexpected operator
我做错了什么?
【问题讨论】:
-
您的实际代码中的命令
read username: "是带有冒号 (:) 和双引号 ("),还是只是复制粘贴错误? -
你的报价也是错误的。应该是
if [ "$username" == mycroft ]; -
shell
[/test相等是=而不是==。 -
@EtanReisner
==在bash中是可以的,但不推荐。 -
你忘记了 hashbang
标签: bash if-statement operator-keyword google-chrome-os crosh