Bash:保存和打印数组中的参数
如何将bash脚本中的所有参数保存到一个数组中并单独打印?初始化数组:Bash:保存和打印数组中的参数,bash,command-line-arguments,Bash,Command Line Arguments,如何将bash脚本中的所有参数保存到一个数组中并单独打印?初始化数组: 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 +1.还可以使用类似C的for
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
+1.还可以使用类似C的for循环来迭代索引:
for((i=0;i<${ARGS[@]};i++);执行printf“%d\t%s\n”$i“${ARGS[i]}”;完成