Skip to content

Instantly share code, notes, and snippets.

@naoki-mizuno
Created October 2, 2018 08:12
Show Gist options
  • Save naoki-mizuno/a81015307e28d186d65dab7308c35ced to your computer and use it in GitHub Desktop.
Save naoki-mizuno/a81015307e28d186d65dab7308c35ced to your computer and use it in GitHub Desktop.
#!/bin/bash
while (( $# > 0 )); do
case "$1" in
-*)
if [[ $1 == -- ]]; then
IGNORE_REST=true
shift
continue
elif [[ -n $IGNORE_REST ]]; then
(( argc++ ))
argv=( "${argv[@]}" "$1" )
shift
continue
fi
OPTIND=${argc:1}
while getopts 'abcdefghijklmnopqrstuvwxyz' flag; do
case "$flag" in
h)
echo "Usage: $0 [-h] [-r]"
;;
*)
echo "$flag found"
;;
esac
done
shift $(( OPTIND - 1 ))
;;
*)
(( argc++ ))
argv=( "${argv[@]}" "$1" )
shift
;;
esac
done
for a in ${argv[@]}; do
echo "> $a"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment