Bash:从数组中保存并打印参数

时间:2012-07-29 17:40:55

标签: bash command-line-arguments

如何将bash脚本中的所有参数保存到数组并单独打印?

1 个答案:

答案 0 :(得分:6)

初始化数组:

ARGS=("$@")              # "$@" gives the arguments passed to the script
ARGS=(arg1 arg2 arg3)    # or fill the array out yourself

显示数组项:

for ARG in "${ARGS[@]}"; do
    printf '%s\n' "$ARG"
done