Created
July 23, 2018 11:53
-
-
Save pawndev/5ce416a3e40e44bd126d129fbc06bfc5 to your computer and use it in GitHub Desktop.
bash cli argument example
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 | |
| params="$(getopt -o hviuc: -l help,version,install,update,clean: --name "$0" -- "$@")" | |
| eval set -- "$params" | |
| . ./lib/echos.sh | |
| usage() { | |
| shrug "Dotfiles Installer" | |
| echo "Usage:" | |
| echo " --help -h -? Display this help message." | |
| echo " --install -i Install a Python package." | |
| echo " --update -u Update a Python package." | |
| echo " --clean -c Clean a Python package." | |
| exit 0 | |
| } | |
| execute="" | |
| specific_package="" | |
| while [[ $# -gt 0 ]] ; do | |
| case $1 in | |
| -h|-\?|--help) | |
| usage | |
| exit | |
| ;; | |
| -v|--version) | |
| if [ -n "$2" ]; then | |
| echo "version: <$2>" | |
| specific_package=$2 | |
| shift | |
| fi | |
| ;; | |
| -i|--install) | |
| execute="INSTALL" | |
| if [ -n "$2" ]; then | |
| echo "install: <$2>" | |
| specific_package=$2 | |
| shift | |
| fi | |
| ;; | |
| -u|--update) | |
| execute="UPDATE" | |
| if [ -n "$2" ]; then | |
| specific_package=$2 | |
| echo "update: <$2>" | |
| shift | |
| fi | |
| ;; | |
| -c|--clean) | |
| execute="CLEAN" | |
| if [ -n "$2" ]; then | |
| specific_package=$2 | |
| echo "clean: <$2>" | |
| shift | |
| fi | |
| ;; | |
| esac | |
| shift | |
| done | |
| case $execute in | |
| "INSTALL") | |
| echo "INSTALL $specific_package" | |
| ;; | |
| "UPDATE") | |
| echo "UPDATE $specific_package" | |
| ;; | |
| "CLEAN") | |
| echo "CLEAN $specific_package" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment