【问题标题】:Chrome OS bash script if statement error如果语句错误,Chrome OS bash 脚本
【发布时间】: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


【解决方案1】:

你的问题在第二行

echo -n "Username: "
read username
if [ $username = "mycroft" ]; then
  echo "Correct!"
fi

【讨论】:

  • 好吧,according to the OP 问题中的代码不是他正在使用的实际代码,因此很难判断问题的真正问题是什么时候。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-30
  • 2023-01-13
  • 1970-01-01
  • 1970-01-01
  • 2014-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多