[::预期的整数表达式错误 [英] [: : integer expression expected Error

查看:117
本文介绍了[::预期的整数表达式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用此脚本时遇到问题,不知道到底发生了什么.

I am having issues with this script and don't know exactly what is happening.

#Main Menu
clear
while [ "$input" -eq "0" ];
do
clear
#$input == 0
echo "Hello, What would you like me to do?"
echo ""
echo "1 = ALL TEH THINGZ!"
echo "2 = Find the enemy postions and villages"
echo "3 = Set the firewalls to my liking"
echo "4 = Confuse the enemy"
echo "5 = Deploy the spies!"
echo "6 = DISABLED Run the TOP SECRET STUFF! (Note password is required)"
echo "81 = Burn the bridges! (Cautian: Last Resort)"
echo "96 = Install/Update Software (locally)"
echo "97 = Install/Update Software (remotely)"
echo "98 = Update and add new Kali tools"
echo "99 = I am done with you for now"
read -p "Select an operation for me to do: " $input

我知道我有fi和右结,但是同时出现错误[[$ input"-eq" 0];

I know I have the fi and end right but I am getting an error at the while [ "$input" -eq "0" ];

推荐答案

如果$input不是合法的数字表达式,则会收到该消息.例如,如果它是空字符串.如果要在0时循环播放,则应先将其设置为0.

You'll get that message if $input is not a legal numeric expression; for instance, if it's the empty string. If you want to loop while it's 0, you should start out by setting it to 0.

input=0
while [ "$input" -eq 0 ]; do 
...
done

尽管您已将此标签标记为bash;如果您实际上正在使用bash,也可以执行以下操作:

Although you've tagged this bash; if you're actually using bash, you can also do this:

while (( input == 0 )); do
 ...
done

请注意,shell不是Perl; $不是变量名的一部分.最好将$视为表示获取...的值"的运算符.变量是input;您用input=分配它;您使用read input对其进行了阅读; .仅当要获取存储在变量中的值时,才使用$input.

Note that shell is not Perl; the $ is not part of the variable name. It's better to think of $ as an operator that means "get the value of". The variable is input; you assign it with input=; you read into it with read input; etc. You only use $input when you want to get the value stored in the variable.

因此,例如,除非存储在input变量中的值是一个字符串,该字符串是某些 other 的名称,否则执行$input=read $input没有任何意义.您要设置其值的变量.

So, for instance, it doesn't make sense to do $input= or read $input unless the value stored in the input variable is a string which is the name of some other variable that you want to set the value of.

这篇关于[::预期的整数表达式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆