GetOpts Parsing Options for #Shellscript


The following lines is a snippet that show how to parse the option parameters in the shell script command ./foo -B -S -i /tmp -o /tmp/out -n 100


BIGLITERAL=no
SF=no
input=""
output="out"
numberofqueries=2
set -- $(getopt BSi:o:n: "$@")
while [ $# -gt 0 ]
do
case "$1" in
(-B) BIGLITERAL=yes;;
(-S) SF=yes;;
(-i) input="$2"; shift;;
(-o) output="$2"; shift;;
(-n) numberofqueries="$2"; shift;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*)  break;;
esac
shift
done

echo $input
echo $output
echo $BIGLITERAL
echo $numberofqueries

if [[ $input == "" ]] || [[ ! -d $input ]]
then
echo "$0: error "
echo "no input"
exit 1
fi

  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s