Created
June 26, 2024 12:46
-
-
Save j3ffml/370650f6792df8d7c4670aff1f16bd07 to your computer and use it in GitHub Desktop.
Simple bash cli wrapper with options that calls another program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -e | |
| usage() { | |
| echo "Usage: $0 [--boolean-option] [--option-with-value=value] -- [args for another program]" | |
| exit 1 | |
| } | |
| option_value="" | |
| boolean_option=0 | |
| for i in "$@"; do | |
| case $i in | |
| --boolean_option) | |
| boolean_option=1 | |
| shift | |
| ;; | |
| --option-with-value=*) | |
| option_value="${i#*=}" | |
| shift | |
| ;; | |
| --) | |
| shift | |
| break | |
| ;; | |
| *) | |
| usage | |
| ;; | |
| esac | |
| done | |
| echo "boolean_option=$boolean_option, option_value=$option_value" | |
| echo "remaining arguments: $@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment