07脚本参数传递
时间:2007-12-16 来源:bluexjj
07脚本参数传递
shift:
*每次将参数位置向左偏移n位
example_01:
#!/bin/bash
#opt2
usage()
{
echo "usage:`basename $0` filenames"
}
totaline=0
if [$# -lt 2]; then
usage
exit
fi while [$# -ne 0]
do
line=`cat $1 | wc -l `
echo "$1 : ${line}"
totalline=$[$totalline + $line]
shift
done echo "______________"
echo "total : ${totalline}" getopts:
*获得多个命令行参数
example_02:
#!/bin/bash
ALL=false
HELP=false
FILE=false
VERBOSE=false
while getopts ahfvc: OPTION
do
case $OPTION in
a)
ALL=true
echo "ALL is $ALL"
;;
h)
HELP=true
echo "HELP is $HELP"
;;
f)
FILE=true
echo "FILE is $FILE"
;;
v)
VERBOSE=true
echo "VERBOSE is $VERBOSE"
;;
c)
c=$OPTARG
echo "c value is $c"
\?)
echo "`basename $0` -[a h f v ] -c "
;;
esac
done
#!/bin/bash
#opt2
usage()
{
echo "usage:`basename $0` filenames"
}
totaline=0
if [$# -lt 2]; then
usage
exit
fi while [$# -ne 0]
do
line=`cat $1 | wc -l `
echo "$1 : ${line}"
totalline=$[$totalline + $line]
shift
done echo "______________"
echo "total : ${totalline}" getopts:
*获得多个命令行参数
example_02:
#!/bin/bash
ALL=false
HELP=false
FILE=false
VERBOSE=false
while getopts ahfvc: OPTION
do
case $OPTION in
a)
ALL=true
echo "ALL is $ALL"
;;
h)
HELP=true
echo "HELP is $HELP"
;;
f)
FILE=true
echo "FILE is $FILE"
;;
v)
VERBOSE=true
echo "VERBOSE is $VERBOSE"
;;
c)
c=$OPTARG
echo "c value is $c"
\?)
echo "`basename $0` -[a h f v ] -c "
;;
esac
done
相关阅读 更多 +