Linux中Shell变量$#,$@,$0,$1,$2,$*,$$,$?的含义
来源:互联网 发布:北京110网络报警平台 编辑:程序博客网 时间:2024/05/22 06:40
我们先来写一个简单的脚本,执行以后再解释各个变量的意义。
# vim var
脚本内容如下:
#!/bin/sh
echo "the number of parameters passed to the script: $#"
echo "the name of the script itself: $0"
echo "the first parameter passed to the shell script: $1"
echo "the second parameter passed to the shell script: $2"
echo "the list of all the parameters passed to the script(some string): $@"
echo "the list of all the parameters passed to the script(one string): $*"
echo "the current process ID number of the script which is running: $$"
echo "the return value of the last shell command performed: $?"
保存退出。
赋予脚本执行权限:
# chmod +x var
执行脚本:
# ./var i j k
the number of parameters passed to the script: 3
the name of the script itself: ./var
the first parameter passed to the shell script: i
the second parameter passed to the shell script: j
the list of all the parameters passed to the script(some string): i j k
the list of all the parameters passed to the script(one string): i j k
the current process ID number of the script which is running: 3746
the return value of the last shell command performed: 0
通过显示结果可以看到:
$# 是传递给脚本的参数个数;
$0 是脚本本身的名字;
$1 是传递给该shell脚本的第一个参数;
$2 是传递给该shell脚本的第二个参数;
$@ 是传递给脚本的所有参数的列表(是多个字符串,每个参数为1个字符串);
$* 是传递给脚本的所有参数的列表(以一个单字符串显示所有参数),与位置变量不同,参数可超过9个;
$$ 是运行脚本的当前进程ID号;
$? 是显示执行上一条Shell命令的返回值,0表示没有错误,其他表示有错误。
0 0
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释:
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义+举例
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释:
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- 2014.3.14号博客学习签到
- iOS开发之不同版本适配问题
- truncate与delete的区别?(deletefrom table和truncate table tablea的区别!)
- html5的几个简单例子
- Android 瀑布流布局
- Linux中Shell变量$#,$@,$0,$1,$2,$*,$$,$?的含义
- jquery实现人物简单走动
- 关于数组
- course3 二分
- UVA-442数据结构调用栈,注意括号的处理
- android canvas drawText \r\n 换行
- 学生信息管理系统 输入和输出 链表
- 设置窗口客户区大小的方法
- java 大数运算 BinInteger