在Linux Shell中遍历参数列表

7
我希望您能够在shell中遍历参数列表,我知道如何使用。
for var in $@

但我想使用以下方式实现:

for ((i=3; i<=$#; i++))

我需要这个是因为前两个参数不会进入循环。有人知道如何做吗?期待您的帮助。
3个回答

11

4

1

虽然这是一个旧问题,但你可以用另一种方法来解决它。也许这就是你要的。

for(( i=3; i<=$#; i++ )); do  
    echo "parameter: ${!i}"  #Notice the exclamation here, not the $ dollar sign.
done

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接