I want to call external application from shell script, but this shell script gets parameters (from other script) in a single variable. All was OK until I did not have to use double quotes for single parameter, but words separated by space.
Here is simplified example of my problem (sh_param just prints all passed parameters):
#!/bin/sh
pass() {
echo "Result with \$@"
./sh_param $@
echo "Result with \"\$@\""
./sh_param "$@"
echo "Result with \$*"
./sh_param $*
echo "Result with \"\$*\""
./sh_param "$*"
}
pass '"single param" separate params'
and results (sh_param just prints all passed parameters):
Result with $@
Param: "single
Param: param"
Param: separate
Param: params
Result with "$@"
Param: "single param" separate params
Result with $*
Param: "single
Param: param"
Param: separate
Param: params
Result with "$*"
Param: "single param" separate params
And I want:
Param: single param
Param: separate
Param: params
Answering my own question. BIG thanks goes to pzanoni.
xargs seems to parse correctly anything you are throwing to it 🙂
“$@”, “$“, $@ and $ works good with it. So my code now looks like:
And result is what I wanted: