I need to write a bash script that, among other things, should pass all its arguments intact to another program.
Minimal example:
$ cat >proxy.sh #!/bin/bash ./script.sh $@ ^D $ chmod +x proxy.sh $ cat >script.sh #!/bin/bash echo one $1 echo two $2 echo three $3 ^D $ chmod +x script.sh
This naïve approach does not work for arguments with spaces:
$ ./proxy.sh "a b" c one a two b three c
Expected:
$ ./proxy.sh "a b" c one a b two c three
What should I write in proxy.sh
for this to happen?
Note that I can't use aliases, proxy.sh
must be a script — it does some stuff before invoking script.sh
.
Quote $@
, making it "$@"
:
$ cat >proxy.sh
#!/bin/bash
./script.sh "$@"
^D
Then it retains the original quotes:
one a b
two c
three
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