I am writing a bash script that takes multiple input variables (7 at maximum), but only the first 4 are mandatory. The remaining 3 are optional and are set already within the script, unless specified when calling the script form the terminal prompt.
My problem comes when I want to change only one of the optional variables. If I want to change the 7th variable, for instance, I have to write down also the 5th and 6th variable values, because otherwise the script will think that this is the 5th argument, and not the 7th, of course. How can I do that?
Here is an example of what this part of my script looks like now:
#!/bin/bash
tstart=$1
tstop=$2
coord1=$3
coord4=$4
optional1=${5:-100}
optional2=${6:-50000}
optional3=${7:-4}
...
When calling the script, if I want to change the variable optional3, I have to write also the vaules of optional1 and optional2. Is there a way similar to:
$ myscript.sh var1 var2 var3 var7=vaule_7
(similar to what you do with default variable values in functions in python)
Thank you very much!!!
Pere.