带变量bash的下行循环

带变量bash的下行循环,bash,Bash,为什么不起作用? 我找不到任何例子搜索谷歌的下降循环…,甚至没有变量。为什么?您应该使用以下命令指定增量: $ cat fromhere.sh #!/bin/bash FROMHERE=10 for i in $(seq $FROMHERE 1) do echo $i done $ sh fromhere.sh $ 您可能更喜欢Bash内置Shell算法,而不是生成外部seq: 为此,Bash有一个for循环语法。无需使用外部seq实用程序 i=10 while (( i >= 1

为什么不起作用?

我找不到任何例子搜索谷歌的下降循环…,甚至没有变量。为什么?

您应该使用以下命令指定增量:

$ cat fromhere.sh
#!/bin/bash

FROMHERE=10

for i in $(seq $FROMHERE 1)
do
echo $i
done
$ sh fromhere.sh
$ 
您可能更喜欢Bash内置Shell算法,而不是生成外部seq:


为此,Bash有一个
for
循环语法。无需使用外部
seq
实用程序

i=10
while (( i >= 1 )); do
    echo $(( i-- ))
done
向下循环(停止播放)

500--->18:04:02
499 ---> 18:04:03
498 ---> 18:04:04
497 ---> 18:04:05
496 ---> 18:04:06
495 ---> 18:04:07
...
...
...
5 ---> 18:12:20
4 ---> 18:12:21
3 ---> 18:12:22
2 ---> 18:12:23
1 ---> 18:12:24
模式:

for ((q=500;q>0;q--));do echo $q ---\>\ `date +%H:%M:%S`;sleep 1;done && pkill mplayer
范例

for (( ... )); do ... ; done
结果

同时: 第一步

10
9
8
7
6
5
4
3
2
1
0
然后

或: “AAA——”变成了while

while ((AAA>=0));do echo $((AAA--));sleep 1;done

“sleep 1”不需要

@marco:但在Bash中,不能在大括号范围表达式中使用变量。
for ((i=10;i>=0;i--)); do echo $i ; done
10
9
8
7
6
5
4
3
2
1
0
AAA=10
while ((AAA>=0));do echo $((AAA--));sleep 1;done
while (( $((AAA-- >= 0)) ));do echo $AAA;sleep 1;done