I am new to bash scripting and struggle to update a parameter with a default value. I observe some of my optional parameters are not getting updated according to the user input.
Below is the interesting part of my bash script. For instance, I set the variable REGISTRATION to 1, then the user can chose to set it to 0 instead.
# default values
DIM=3
BIASFIELDCORRECTION=1
SKULLSTRIPPING=0
REGISTRATION=1
RESAMPLRES=0
# reading command line arguments
while getopts ":s:d:b:res:reg:h:" OPT
  do
  case $OPT in
      h) #help
   Help
   exit 0
   ;;
      d)  # dimension
   DIM=$OPTARG
   ;;
      b)  # bias field correction
   BIASFIELDCORRECTION=$OPTARG
   ;;
      s)  # skull stripping
   SKULLSTRIPPING=$OPTARG
   ;;
      res)  # resampling resolution
   RESAMPLRES=$OPTARG
   ;;
      reg)  # resampling resolution
   REGISTRATION=$OPTARG
   ;;
     \?) # getopts issues an error message
   exit 1
   ;;
  esac
done
echo "Registration:" $REGISTRATION
The problem is that the last line always outputs Registration: 1, even when the user set the variable to 0 with the following syntax:
bash preprocessingPipeline.sh -reg 0
I checked all my parameters and it appears that only res, reg and s present this problem. d and b are correctly updated. Can someone tell my what's wrong with my approach?
