+ -
当前位置:首页 → 问答吧 → bash中的传入参数取值问题

bash中的传入参数取值问题

时间:2011-10-14

来源:互联网

代码如下:

Python code
#!/bin/sh

i=1

while [ $i -le $# ]
do
    #是下行有问题
    echo ${$i}
    i=`expr $i + 1`
done


带参数传入后,错误提示为:
Python code
./a.sh: 9: Bad substitution


我就是想逐个取传入的参数,但貌似${$i}是错误的。

谁能帮帮我?

作者: guofengnuli   发布时间: 2011-10-14

囧,用while实现C语言的for循环?
google下shell for loop

作者: iambic   发布时间: 2011-10-14