gpt4 book ai didi

linux - 错误 : While loop in bash shell script

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:23 25 4
gpt4 key购买 nike

我正在尝试运行名为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com