Skip to content

Instantly share code, notes, and snippets.

@j3ffml
Created June 26, 2024 12:46
Show Gist options
  • Select an option

  • Save j3ffml/370650f6792df8d7c4670aff1f16bd07 to your computer and use it in GitHub Desktop.

Select an option

Save j3ffml/370650f6792df8d7c4670aff1f16bd07 to your computer and use it in GitHub Desktop.
Simple bash cli wrapper with options that calls another program
#!/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