How to iterate over arguments in a Bash script

后端 未结 8 2587
长发绾君心
长发绾君心 2020-11-22 02:27

I have a complex command that I\'d like to make a shell/bash script of. I can write it in terms of $1 easily:

foo $1 args -o $1.ext
         


        
8条回答
  •  无人及你
    2020-11-22 03:32

    aparse() {
    while [[ $# > 0 ]] ; do
      case "$1" in
        --arg1)
          varg1=${2}
          shift
          ;;
        --arg2)
          varg2=true
          ;;
      esac
      shift
    done
    }
    
    aparse "$@"
    

提交回复
热议问题