I've got the following bash two scripts
a.sh:
#!/bin/bash ./b.sh 'My Argument'
b.sh:
#!/bin/bash someApp $*
The someApp binary receives $*
as 2 arguments ('My' and 'Argument') instead of 1.
I've tested several things:
b.sh
works as expectedb.sh
works as expected$@
instead of $*
doesn't make a differenceYou should just quote the second argument. Show activity on this post. If calling from any Unix shell, and the parameter has spaces, then you need to quote it. You should also quote every variable used within the function/script.
You can put double-quotes around an argument in a java command, and that will allow you to pass arguments with spaces in them.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
$*
, unquoted, expands to two words. You need to quote it so that someApp
receives a single argument.
someApp "$*"
It's possible that you want to use $@
instead, so that someApp
would receive two arguments if you were to call b.sh
as
b.sh 'My first' 'My second'
With someApp "$*"
, someApp
would receive a single argument My first My second
. With someApp "$@"
, someApp
would receive two arguments, My first
and My second
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With