如果条件语法错误 [英] if condition syntax error
本文介绍了如果条件语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个简单的脚本来检查,如果一个号码是20和30之间:
I wrote a simple script to check if a number is between 20 and 30:
while true
do
echo 'enter a number between 20 and 30'
read e
if [ $e -lt 30] && [$e -gt 20 ]
then
echo ' you entered desired number' && break
fi
done
,但它有一个错误,如下所示:
but it has a error as follows:
第5行:[:缺少']'
line 5: [: missing `]'
去哪里错了?
推荐答案
您在这里需要一个空格:
You need a space here:
if [ $e -lt 30 ] && [ $e -gt 20 ]
^ ^
| |
| |
---------------------
总是尝试和运行在调试模式下bash脚本。要以调试模式运行脚本,只需做以下的命令提示符。
Always try and run the bash script in debug mode. To run your script in debug mode, simply do the following on your command prompt.
的bash -x scriptname.sh
这篇关于如果条件语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文