3

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

4

1 回答 1

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
于 2012-07-29T17:47:35.767 回答