I've got a script that takes a variable number of parameters. I also have a wrapper script where I take the same parameters and add some more. The problem is that when I have params with spaces they get split by words when passed to the "inside" script.
For example the outside script:
# tst1.sh
echo "-- tst1.sh --"
echo "1: $1"
echo "2: $2"
./tst2.sh $* --some --more --params
And the inside script:
#!/bin/bash
echo "-- tst2.sh --"
echo "1: $1"
echo "2: $2"
Now when I call the wrapper script it gets the date correct as a single parameter, however the inside one only gets the first word:
$ ./tst1.sh --date "$(date)"
-- tst1.sh --
1: --date
2: Fri Jan 25 21:51:57 GMT 2019
-- tst2.sh --
1: --date
2: Fri <== this is wrong
I want the output of the second script the same as the first one. And all that for a variable number of parameters, that's why I use $*
and not individual $1
, $2
, etc that I could quote.
I tried quoting "$*"
but that then joins the --date
and the actual date string as a single parameter.
Any idea how to do that?