Linux shell参数
来源:互联网 发布:华为数据存储解决方案 编辑:程序博客网 时间:2024/04/28 18:03
在shell编程时.可以使用参数。Shell有位置参数和内部参数
1、位置参数
由系统提供的参数称为位置参数。位置参数的值可以用$N得到,N是一个数字,如果为1,即$1.类似C语言中的数组,Linux会把输入的命令字符串分段并给每段进行标号,标号从0开始。第0号为程序名字,从1开始就表示传递给程序的参数。如$0表示程序的名字,$1表示传递给程序的第一个参数,以此类推。
2、内部参数
上述过程中的$0是一个内部变量,它是必须的,而$1则可有可无。和$0一样的内部变量还有以下几个。
$# ----传递给程序的总的参数数目
$? ----上一个代码或者shell程序在shell中退出的情况,如果正常退出则返回0,反之为非0值。
$* ----传递给程序的所有参数组成的字符串。
下面举例进行说明
[root@server tmp]# cat test.sh
#!/bin/bash
#test shell
echo $0
echo $1
echo $2
echo $?
echo $*
echo $#
[root@server tmp]# ./test.sh yema Bhanv edu network
./test.sh //程序名称
Yema //第一个参数
Bhanv //第二个参数
0 //程序执行结果
yema Bhanv edu network //传递参数所组成的字符串
4 //参数个数
- Linux shell参数
- Linux shell参数
- linux shell if 参数
- linux shell if 参数
- linux shell if 参数
- Linux Shell参数替换
- linux shell if 参数
- linux shell 参数传递
- linux shell if 参数
- Linux shell if参数
- linux shell if 参数
- linux shell if 参数
- linux shell if 参数
- Linux Shell 之 $参数
- linux shell if 参数
- linux shell if 参数
- linux shell if 参数
- linux shell if 参数
- Linux fork与vfork的深入分析
- __declspec关键字详细用法
- c# 获取相对路径
- 求水仙花数和回文的判断
- hadoop配置文件问题
- Linux shell参数
- 关于font face="Webdings"的用法
- hdu 4158 GO
- 纯新手DSP编程--5.31--DSP/BIOS中的数据交换
- CATransition的动画效果类型及实现方法
- 订书器
- js性能测试——for循环
- faye 如何push json数据到客户端?
- IIC