Created
October 2, 2018 08:12
-
-
Save naoki-mizuno/a81015307e28d186d65dab7308c35ced to your computer and use it in GitHub Desktop.
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 | |
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