Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: Save and print arguments from an array

How do you save all the arguments in a bash script to an array and print them individually?

like image 704
SharkTiles Avatar asked Apr 07 '26 16:04

SharkTiles


1 Answers

Initialize the array:

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

Display the array items:

for ARG in "${ARGS[@]}"; do
    printf '%s\n' "$ARG"
done
like image 102
John Kugelman Avatar answered Apr 22 '26 12:04

John Kugelman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!