optional – Bash function with dry-run and exec options

Am writing a bash function to run rsync, with possibility of using --dry-run option and --exec option. Need some criticism improvements and additional checks.

Might not make much sense for the user to specify both --dry-run and --exec. I would simply use –dry-run anyway.

Have started with the following setup.

filetr-archive ()
{
  # Process command line options
  shortopts="nel:s:d:"
  longopts="dry-run,exec,log:,source:,destin:"
  opts=$(getopt -o "$shortopts" -l "$longopts"  
        -n "$(basename $0)" -- "$@")
  if ( $? -eq 0 ); then
    eval "set -- ${opts}"
    while ( $# -gt 0 ); do
      case "$1" in
      -n|--dry-run)
        shift 1
        local -r dryrun=1
        ;;
      -e|--exec)
        shift 1
        local -r exec=1
        ;;
      -l|--log)
        local logfl=$2
        shift 2
        ;;
      -s|--source)
        local source=$2
        shift 2
        ;;
      -d|--destin)
        local destin=$2
        shift 2
        ;;
      --)
        shift;  break  ;;
      esac
    done
  else
    shorthelp=1 # getopt returned (and reported) an error.
  fi

  if (( filetr_dryrun == 1 )); then 

    echo "rsync -av --progress --log-file=$logfl --dry-run"
    echo "  $source $destin"
    rsync -av --progress --log-file=$logfl --dry-run $source $destin

  elif (( filetr_exec == 1 )); then
      
    # use rsync archive option -a (equivalent to -rlptgoD)
    echo "rsync -av --progress --log-file=$logfl $source $destin"
    # rsync -av --progress --log-file=$logfl $source $destin

  else

    echo "rsync -av --progress --log-file=$logfl $source $destin"
      
  fi