3 ms·
Here are two lesser-know tricks that can be quite handy: Using () instead of {} for the functions body allows to isolate it: foo=5 bar() ( cd /
by zimbatm 8y ago
Here are two lesser-know tricks that can be quite handy:
Using () instead of {} for the functions body allows to isolate it:
foo=5
bar() (
cd /
foo=7
)
bar
echo $PWD # not / but the current directory
echo $foo # still 5
Bash 4.0 can splat array of arguments back into a valid bash string with @Q. This is super useful when you need to stop using arrays, like with `bash -c`
ary=("arg1" "arg 2")
echo "${ary[*]@Q}"
# outputs: 'arg1' 'arg 2'