本文介绍了bash中的简单while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开始学习bash脚本.我编写了简单的while循环,但是没有用.有人说:找不到命令.有人知道为什么吗?这是我的代码:
I've started learning bash scripting. I wrote simple while loop, but it doesn't work.it's say that : command not found.does anybody knows why ?Here is my code:
let x=5; while [$x -lt 10];do echo "x is : $x";let x=$x+1; done
推荐答案
添加空格.
while [ $x -lt 10 ];
有关更多信息,请参见如何使用双括号或单括号,括号,花括号的答案:
For more information, please see this answer to How to use double or single bracket, parentheses, curly braces:
$ VARIABLE=abcdef
$ if [ $VARIABLE == abcdef ] ; then echo yes ; else echo no ; fi
yes
此外,这是信息测试
在此问题上必须说的:
Also, this is what info test
has to say on the matter:
因此,等效项如下所示:
Therefore, the equivalent would look like:
let x=5; while test $x -lt 10;do echo "x is : $x";let x=$x+1; done
这篇关于bash中的简单while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!