linux - 错误 : While loop in bash shell script

标签 linux bash shell do-while

我正在尝试运行名为 test.sh 的简单脚本,该脚本以升序方式回显 数字。但不知何故它显示错误。

#!/bin/bash

clear
a= 0

while [ $a <= 5 ];
do
    echo $a
    a=$(( a+1 ))
done

错误:

./test.sh: line 4: 0: command not found
./test.sh: line 6: =: No such file or directory

最佳答案

Anubhava 已经提到了更好的方法,但这是您答案的正确版本。

#!/bin/bash

clear
a=0

while [[ "$a" -lt 5 ]];
do
    echo $a
    a=$(($a+1))
done

关于linux - 错误 : While loop in bash shell script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37071470/

相关文章:

bash - 如何在 Bash 中连接文件中的所有行?

linux - 如何直接操作 PWD?

linux - 如何使用静态 IP 地址设置主机和 httpd.conf 文件

c++ - 使用哪种语言来实现一些 Linux shell 命令(作业)——纯 C 还是 C++?

linux - 使用os161 mips编译的gdb-7.8的链接错误

linux - 检查 Unix 中的变量是否包含文件 bash shell 中提到的任何字符串

python - 如何安装pygame字体

linux - 使用 sed 将 crontab 文件中的文本替换为斜线

linux - 从压缩的内核镜像中获取内核版本

python - 一种使用脚本对数字进行分组的方法