If scriptA
calls scriptB
like
scriptB "$@"
then the command line arguments that were used for invoking scriptA
will be passed to scriptB
provided that these have not been altered before the call.
Likewise for the call from scriptB
to scriptC
.
As long as scriptA
and scriptB
does not try to interpret, change or otherwise mutate the contents of $@
(or the individual positional parameters $1
, $2
, $3
etc.), the command line arguments will be passed on to scriptC
for it to parse with getopt
.
Example using functions instead of scripts (it works the same way):
#!/bin/sh
scriptC () {
printf 'Arg: %s\n' "$@"
}
scriptB () {
scriptC "$@"
}
scriptA () {
scriptB "$@"
}
scriptA -param1 -param2
This will produce the output
Arg: -param1
Arg: -param2
Doing the call as
scriptA "hello world" --param1 /etc/passwd --param2
will produce
Arg: hello world
Arg: --param1
Arg: /etc/passwd
Arg: --param2
That is, the parameters will be passed on to scriptC
without modification. It is then left to scriptC
to interpret the parameters using getopt
, getopts
or by some other means.
getopt(1)
is outdated since 1986, better use the standardizedgetopts(1).