linux中shell变量$#,$@,$0,$1,$2的含义解释(转)
2024-05-11 20:56:47
变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 $@ 所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 $# 添加到Shell的参数个数 $0 Shell本身的文件名 $1~$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 |
示例:
1 #!/bin/bash
2 #
3 printf "The complete list is %s\n" "$$"
4 printf "The complete list is %s\n" "$!"
5 printf "The complete list is %s\n" "$?"
6 printf "The complete list is %s\n" "$*"
7 printf "The complete list is %s\n" "$@"
8 printf "The complete list is %s\n" "$#"
9 printf "The complete list is %s\n" "$0"
10 printf "The complete list is %s\n" "$1"
11 printf "The complete list is %s\n" "$2
|
结果:
[Aric@localhost ~]$ bash params .sh 123456 QQ
The complete list is 24249
The complete list is
The complete list is 0
The complete list is 123456 QQ
The complete list is 123456
The complete list is QQ
The complete list is 2
The complete list is params .sh
The complete list is 123456
The complete list is QQ
|
Have a nice day!!!
最新文章
- CD管理和检索软件比较
- 安装和配置SQL Server 2016 With SP1
- python 字符串format使用
- 解决IE6中PNG图出现灰色背景问题
- 转:ibatis配置简介
- JAVA收到网络报文的IP是::1,怎么回事?
- 来,创建一个高效的IMEI编码生成器
- 浅谈无线传感器和无线传感器网络
- 多元线性回归分析spss结果解读_多重线性回归分析SPSS操作与解读
- DCT--离散余弦变换
- KANBAN专题一:KANBAN管理的基本系统操作
- 99% 的程序员想不到的一个技巧,绝对让领导眼前一亮,好感倍增!
- 从容不迫——《稀缺》的读书笔记范文3700字
- go 获得 mysql 实际运行 SQL_mysql对标准sql的goup by进行了扩展 | 学步园
- 联发科服务器芯片,基于MTK7623N芯片的香蕉派 BPI-R2 ,智能通信物联网网关开发平台...
- oracle的crs是什么,Oracle CRS简介
- 推荐系统常用的评价指标:HR、NDCG、MRR
- Leetcode:701. 二叉搜索树中的插入操作(C++)
- drcom linux怎么运行,解决64位Ubuntu Linux下不能使用drcom上网的3种方法(下)
- 高通QAC4012平台 支持三大物联网标准