3
如何將bash腳本中的所有參數保存到數組中並單獨打印它們?Bash:保存並打印數組中的參數
如何將bash腳本中的所有參數保存到數組中並單獨打印它們?Bash:保存並打印數組中的參數
初始化數組:
ARGS=("[email protected]") # "[email protected]" 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((i = 0; i <$ {#ARGS [@]}; i ++));做printf「%d \ t%s \ n」$ i「$ {ARGS [i]}」; done' – 2012-07-29 21:49:32