I would like to copy all the arguments supplied to the Bash script (the special variable $@
), in order to export them. I've attempted this code:
### my_script.sh
echo "Case 1:"
for var in "$@"
do
echo "$var"
done
echo ""
echo "Case 2:"
export a="$@"
for var in $a
do
echo "$var"
done
Unfortunately, calling it with my_script.sh "abc" "de f" "ghi" "j k"
will produce the wrong output: the spaces are breaking the arguments list. How can I copy the arguments of $@
?
Case 1:
abc
de f
ghi
j k
Case 2:
abc
de
f
ghi
j
k