I am writing a very simple script that calls another script, and I need to propagate the parameters from my current script to the script I am executing.
For instance, my script name is foo.sh
and calls bar.sh
foo.sh:
bar $1 $2 $3 $4
How can I do this without explicitly specifying each parameter?
My SUN Unix has a lot of limitations, even "$@" was not interpreted as desired. My workaround is ${@}. For example,
By the way, I had to have this particular script because my Unix also does not support grep -r
I realize this has been well answered but here's a comparison between "$@" $@ "$*" and $*
Contents of test script:
Now, run the test script with various arguments:
Use
"$@"
instead of plain$@
if you actually wish your parameters to be passed the same.Observe:
If you include
$@
in a quoted string with other characters the behavior is very odd when there are multiple arguments, only the first argument is included inside the quotes.Example:
Yields:
But assigning to a different variable first:
Yields:
Just thought this may be a bit more useful when trying to test how args come into your script
For bash and other Bourne-like shells: