$@ instead of $* in bash functions
#!/bin/bash
# $* is a single string whereas $@ is an array.
# Using "$*"
for a in "$*"; do
echo $a;
done
# Result:
# one two three four
#-------------------------
# Using $*
for a in $*; do
echo $a;
done
# Result:
# one
# two
# three
# four
#-------------------------
# Using "$@"
for a in "$@"; do
echo $a;
done
# Result:
# one
# two
# three four
#-------------------------
# Using $@
for a in $@; do
echo $a;
done
# Result:
# one
# two
# three
# four
Are there any code examples left?
New code examples in category Shell/Bash