There are lots of ways to parse arguments in sh. Getopt is good. Here's a simple script that parses things by hand:
#!/bin/sh
while echo $1 | grep -q ^-; do
eval $( echo $1 | sed 's/^-//' )=$2
shift
shift
done
echo host = $host
echo user = $user
echo pass = $pass
echo args = $@
A sample run looks like:
$ ./a.sh -host foo -user me -pass secret some args host = foo user = me pass = secret args = some args
转自: http://stackoverflow.com/questions/4882349/parsing-shell-script-arguments