How can I make bash deal with long param using “getopt” command in mac?

后端 未结 3 800
不思量自难忘°
不思量自难忘° 2021-02-07 01:06

I want to make my bash script deal with long parameters. I found getopt, but it isn\'t supported in OS X. Can anyone tell me why getopt was implemented

3条回答
  •  清酒与你
    2021-02-07 01:37

    I recommend using Homebrew to install gnu-getopt and then adding $FLAGS_GETOPT_CMD to your ~/.bash_profile file to specify the cmd path for getopt, pointing at the homebrew location, like so:

    brew install gnu-getopt
    

    Then follow directions from brew to add to your local path:

    sudo echo 'export PATH="/usr/local/opt/gnu-getopt/bin:$PATH"' >> ~/.bash_profile
    

    Then you can add FLAGS_GETOPT_CMD:

    sudo echo 'export FLAGS_GETOPT_CMD="$(brew --prefix gnu-getopt)/bin/getopt"' >> ~/.bash_profile
    

    Open a new terminal, or run . ~/.bash_profile in existing terminal to load changes

    Run echo $FLAGS_GETOPT_CMD to confirm it was actually set in your console

提交回复
热议问题