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
- The getopts are
.:o.:t.:k.:r(r is not used in current run) - 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?
You can do
./slave ${*/Arg1/Arg2}. This will send all the arguments frommastertoslave, after replacingArg1withArg2. The nice thing is that$*evaluates all your inputs as one string (unlike$@), allowing for a simple replacement.