在编写 shell 脚本的过程中,我遇到了以下 if/else 语句的问题,该语句位于脚本中间的某个位置:
if [ $act -eq "add" ]
then
read - "add or update: " $comm
git commit -m "$comm $file"
else
git commit -m "$act $file"
fi
Run Code Online (Sandbox Code Playgroud)
返回的错误是:
./gitup: line 13: [: add: integer expression expected
Run Code Online (Sandbox Code Playgroud)
然后继续执行脚本的其余部分。如何让 if 段评估/比较变量与字符串输入而不是整数;在我尝试的其他一些事情中使用“!=”时需要一个不同的错误。