https://github.com/stevearc/parseargs
Bash utility for parsing commandline arguments
https://github.com/stevearc/parseargs
Last synced: about 2 months ago
JSON representation
Bash utility for parsing commandline arguments
- Host: GitHub
- URL: https://github.com/stevearc/parseargs
- Owner: stevearc
- License: mit
- Created: 2015-10-14T04:14:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-11T16:46:08.000Z (over 7 years ago)
- Last Synced: 2025-01-03T01:44:33.862Z (about 2 months ago)
- Language: Shell
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# parseargs
[](https://travis-ci.org/stevearc/parseargs)Bash utility for parsing commandline arguments inspired by [docopt](http://docopt.org/)
Requires bash>=4.0
Example:
```bash
# Set the USAGE environment variable
USAGE="$0 [] [...]Options:
-s Short flag
-a ARG Short arg
--long Long flag
--longarg=LARG Long arg
-f, --flag Short & long flag
-r RARG, --arg=RARG Short & long arg
"source parseargs.sh
parseargs "$@"
# Now all the args are set as environment variables
echo "Required arg: $REQUIRED_ARG"
[ -n "$OPTIONAL_ARG" ] && echo "Optional arg: $OPTIONAL_ARG"
[ -n "$OPT_REPEATING_ARG" ] && echo "Optional repeating arg: $OPT_REPEATING_ARG"
[ -n "$S" ] && echo "short flag set"
[ -n "$ARG" ] && echo "short arg set: $ARG"
[ -n "$LONG" ] && echo "long flag set"
[ -n "$LARG" ] && echo "long arg set: $LARG"
[ -n "$FLAG" ] && echo "short/long flag set"
[ -n "$RARG" ] && echo "short/long arg set: $RARG"
```You can also pass the usage string in directly if you'd prefer not to set `USAGE`:
```bash
myusage="$0 ..."
parseargs "$myusage" "$@"
```