collecting all options in shell

96 Views Asked by At

I'm trying to forward all the options collected to be used in another command in shell script.

For example if a script is run like:

./master -o -t -k Arg1

In master

  1. The getopts are .:o.:t.:k.:r (r is not used in current run)
  2. runs another scrip and all the options used for should be used for the internal script
./slave -o -t -k Arg2

I want all the (-o -t -k), or any other options combination entry to be used - how do I do that?

1

There are 1 best solutions below

1
On

You can do ./slave ${*/Arg1/Arg2}. This will send all the arguments from master to slave, after replacing Arg1 with Arg2. The nice thing is that $* evaluates all your inputs as one string (unlike $@), allowing for a simple replacement.