文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个很有意思的位置参数脚本

一个很有意思的位置参数脚本

时间:2010-09-14  来源:qingchn

刚刚看到一个很有意思的解释shell中位置参数的脚本,先记下来,也略作说明

#!/bin/bash
#positional paraments_test
MINPARAMS=10
echo
echo "The name of this scrppt is \"`basename $0`\"."   #返回脚本说明 $0指的是脚本名称
echo
if [ -n "$1" ]         # if语句没有说明好说的  $1
then
echo  "Parameter #1 is $1"
fi


if [ -n "$2" ]
then
echo  "Parameter #2 is $2"
fi

if [ -n "$3" ]
then
echo  "Parameter #3 is $3"
fi

if [ -n "${10}" ]
then
echo  "Parameter #10 is ${10}"  #位置参数只有9个  大于9的参数就必须出现在{}中
fi

echo "------------------"
echo "All the command-line parameters are:"$*""   # 其中$*指的是所有位置参数 同$@

echo
if [ $# -lt "$MINPARAMS" ]   #这里的$#指的是传递到脚本中的位置参数的个数
then
 echo
 echo  "This script needs at last $MINPARAMS commoand-line arguments"
fi
 echo
 exit 0
##End script#
运行上面的脚本[root@test6 testshell]# ./weizhicanshu.sh  1 2 3 4 5 6 7 8 9 10

The name of this scrppt is "weizhicanshu.sh".

Parameter #1 is 1
Parameter #2 is 2
Parameter #3 is 3
Parameter #10 is 10
------------------
All the command-line parameters are:1 2 3 4 5 6 7 8 9 10


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载