Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217081
  • 博文数量: 88
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 555
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-03 13:08
个人简介

失意高调,得意低调

文章分类

全部博文(88)

文章存档

2021年(3)

2020年(2)

2018年(2)

2017年(3)

2016年(6)

2015年(19)

2014年(32)

2013年(21)

我的朋友

分类: LINUX

2014-05-20 13:52:24

  1. #!/bin/bash
  2. funWithParam(){
  3. echo "The value of the first parameter is $1 !"
  4. echo "The value of the second parameter is $2 !"
  5. echo "The value of the tenth parameter is $10 !"
  6. echo "The value of the tenth parameter is ${10} !"
  7. echo "The value of the eleventh parameter is ${11} !"
  8. echo "The amount of the parameters is $# !"
  9. echo "The string of the parameters is $* !"
  10. }
  11. funWithParam 1 2 3 4 5 6 7 8 9 34 73

输出:
The value of the first parameter is 1 !
The value of the second parameter is 2 !
The value of the tenth parameter is 10 !
The value of the tenth parameter is 34 !
The value of the eleventh parameter is 73 !
The amount of the parameters is 12 !
The string of the parameters is 1 2 3 4 5 6 7 8 9 34 73 !"

注意,$10 不能获取第十个参数,获取第十个参数需要${10}。当n>=10时,需要使用${n}来获取参数。

另外,还有几个特殊字符用来处理参数:
参数处理 说明
$# 传递到脚本的参数个数
$* 以一个单字符串显示所有向脚本传递的参数
$$ 脚本运行的当前进程ID号
$! 后台运行的最后一个进程的ID号
$@ 与$#相同,但是使用时加引号,并在引号中返回每个参数。
$- 显示Shell使用的当前选项,与set命令功能相同。
$? 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误

阅读(627) | 评论(0) | 转发(0) |
0

上一篇:脚本

下一篇:libpcap嵌入式linux的移植

给主人留下些什么吧!~~