Skip to content

Instantly share code, notes, and snippets.

@redtower
Created January 13, 2011 14:45
Show Gist options
  • Save redtower/777958 to your computer and use it in GitHub Desktop.
Save redtower/777958 to your computer and use it in GitHub Desktop.
シェルスクリプトでのコマンドラインオプションの処理
#!/bin/sh
while getopts ab:c: opt
do
case $opt in
a)
flga=1
;;
b)
flgb=1
optb=$OPTARG
;;
c)
flgc=1
optc=$OPTARG
;;
\?)
;;
esac
done
shift $(($OPTIND - 1))
#!/bin/sh
OPT=`getopt -n $0 -o ab:c: --long aaa,bbb:,ccc: -- "$@"`
eval set -- "$OPT"
while true;
do
case $1 in
-a|--aaa)
opt_a=true
;;
-b|--bbb)
opt_b=$2
;;
-c|--ccc)
opt_c=true
;;
--)
break
;;
esac
shift
done
echo $opt_a
echo $opt_b
echo $opt_c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment