Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 488 Bytes

bash-pass-argument-to-sub-command.md

File metadata and controls

30 lines (25 loc) · 488 Bytes

Bash pass env variable to subcommand

Back

getopts parses till --, by shifting by $OPTIND - 1 the remaining params can be passed

# <script> -a "something" -- -passed -on args

while getopts "a:h?" opt
  do
    case "$opt" in
    [h?])
      help_build
      exit 0
      ;;
    # get opt code
    a)
      # Some handling
      ;;
    *)
      help_build
      exit 1
      ;;
    esac
  done

  shift $(($OPTIND - 1))
  echo "Args passed $@"