function f() {
for arg; do
echo "$arg"
done
}
f 'hello world' 'second arg' '3rdarg'
this works fine:
hello world
second arg
3rdarg
but when do I assign $@
to some variable, and then it goes wrong:
function f() {
local args="$@"
for arg in "$args"; do
echo "$arg"
done
}
output:
hello world second arg 3rdarg
when I unquote the $args
, then each argument was split into single word:
hello
world
second
arg
3rdarg
Lastly, I wonder if there's a way to define variable like $@. Any response will be appreciated.