There are 4 bash snippets below. I call them with ./script.sh a b c
for arg in $@; do
echo "$arg"
done ## output "a\nb\nc"
for arg in "$@"; do
echo "$arg"
done ## output "a\nb\nc" -- I don't know why
for arg in $*; do
echo "$arg"
done ## output "a\nb\nc"
for arg in "$*"; do
echo "$arg"
done ## output "abc"
I don't know what is the exact difference between $@
and $*
,
and I think "$@"
and "$*"
should be the same, but they are not. Why?