Option parse code for POSIX-compliant shell scripts that high function and short.
Implements step by step.
- option1.sh: Supports flag option and parameters only
- option2.sh: Supports option argument
- option3.sh: Supports a mixture of options and operands
- option4.sh: Stop option parsing with --
- option5.sh: Supports combined short options
- option6.sh: Supports combined option and argument
- option7.sh: Supports optional option argument
- option8.sh: Inverse flag option with +, --no-
Note: This sample reuses the OPTIND
and OPTARG
variables for other purposes.
Explanation is in Japanese only, sorry.
Tested by shellspec.
Unlicense. Feel free to use it.