In Bash I can set $@
this way:
set -- a b c
Then, I can inspect the content of $@
:
printf '%s\n' "$@"
which would show:
a
b
c
However, if I do this in a function:
f() {
set d e f
}
set a b c
f
printf '%s\n' "$@"
I still get
a
b
c
and not
d
e
f
How can I make my function update caller's $@
? I tried with BASH_ARGV, but it didn't work.
I am trying to write a function that processes the command line arguments and removes certain items from there (while setting a variable) so that the caller doesn't need to bother about them. For example, I want all my scripts to turn on their debug logging if I invoke them with --debug
without having to write the code to process that in each script and placing that logic in a common "sourced" function instead.
Note: I don't want to fork a subshell.