I know that there are variations of this concept, but I haven't found a case where there is a script that takes in a bunch of arguments via flags that is called by another script. How can I avoid duplicate arguments that need to be maintained? Example:
script-to-be-called.sh
takes in arguments like this:
function get_user_args() {
while getopts ":a:b:c:" opt; do
case ${opt} in
h )
usage
;;
a )
abc=$OPTARG
;;
b )
efg=$OPTARG-`uuidgen`
;;
c )
hi=$OPTARG
;;
...
\? )
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
}
Running it on its own looks like this:
./script-to-be-called -a xyz -b mno -c helloworld
So, now if I have a wrapper script that calls it, how can I avoid having an identical get_user_args
function? For example, how can wrapper-script.sh
run as shown below where users can pass in arguments in the same way as above without duplicating the get_user_args function.
function generate_parallel_runs() {
while read params
do
echo "./script-to-be-called -a $argA -b $argB -c $argC" >> parallel_commands_list.sh
done < params.txt
parallel < "parallel_commands_list.sh"
#once the parallel runs are created, remove the file
rm parallel_commands_list.sh
}
Ideally:
./wrapper-script.sh -a xyz -b mno -c helloworld