Shell脚本使用for编写参数

时间:2014-11-27 19:51:51

标签: shell for-loop parameters sh

for (( i=1; i<=$#; i++ ))
do
    echo "$($i)"    <---this is not correct, how should i fix that?
done

我想打印所有参数。

1 个答案:

答案 0 :(得分:2)

for arg; do
    echo "$arg";
done

for ((i=0; i<=${#@}; i++ )); do
    echo "${!i}"
done

for arg in "$@"; do
    echo "$arg";
done