足球游戏_中国足彩网¥体育资讯$

Shell 函数参数
来源:易贤网 阅读:1602 次 日期:2014-09-25 11:55:59
温馨提示:易贤网小编为您整理了“Shell 函数参数”,方便广大网友查阅!

在shell中,调用函数时可以向其传递参数。在函数体内部,通过 $n 的形式来获取参数的值,例如,$1表示第一个参数,$2表示第二个参数...

带参数的函数示例:

?1234567891011 #!/bin/bash funWithParam(){ echo "The value of the first parameter is $1 !" echo "The value of the second parameter is $2 !" echo "The value of the tenth parameter is $10 !" echo "The value of the tenth parameter is ${10} !" echo "The value of the eleventh parameter is ${11} !" echo "The amount of the parameters is $# !" echo "The string of the parameters is $* !"} 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表示没有错误,其他任何值表明有错误。

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看脚本栏目
易贤网手机网站地址:Shell 函数参数
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标