I am trying to create a simple bash function that uses 2 command line parameters. -v for verbosity and -d for a date.
I want to use verbosity false as default and todays date as default for -d.
Now if I provide actual other values, my defaults dont get overwritten. Here is an example output:
$ cruns -v -d 2019-09-10
2019-09-12
false
if check
test false
The date output should be sept. 10th instead of 12th.
And here is my code:
EDIT: I fixed the variable assignment $, but the output still does not use my provided parameters.
cruns(){
local VERBOSE=false
local STARTDATE="$(date +"%Y-%m-%d")"
while getopts "vd:" option; do
case $option
in
v) VERBOSE=true
;;
d) STARTDATE=$OPTARG
;;
esac
done
echo $STARTDATE;
echo $VERBOSE;
echo "if check"
if $VERBOSE; then
echo "test true";# cjobs $STARTDATE | awk -F"_AS-|_Und|_all" '{a[$1]++} END{for(x in a){print x}}'
else
echo "test false";# cjobs $STARTDATE | awk -F"__|_AS-|_Und|_all" '{a[$2]++} END{for(x in a){print x}}'
fi
}
EDIT: I fixed the variable assignment $, but the output still does not use my provided parameters. I store the function in my bashrc, source bashrc and call the function from terminal if this is of importance.
What do I need to change to make the variables get filled with the provided commandline parameters in my getopts case?