当前位置:网站首页>Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$
Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$
2022-07-01 08:36:00 【小蜗牛的路】
| 变量 | 含义 |
|---|---|
| $0 | 当前脚本的文件名。 |
| $n(n≥1) | 传递给脚本或函数的参数。n 是一个数字,表示第几个参数。例如,第一个参数是 $1,第二个参数是 $2。 |
| $# | 传递给脚本或函数的参数个数。 |
| $* | 传递给脚本或函数的所有参数。 |
| [email protected] | 传递给脚本或函数的所有参数。当被双引号" "包含时,[email protected] 与 $* 稍有不同 |
| $? | 上个命令的退出状态,或函数的返回值 |
| $$ | 当前 Shell 进程 ID。对于 Shell 脚本,就是这些脚本所在的进程 ID。 |
$*与 [email protected]不同点:当被双引号包裹时,[email protected]与没有被双引号包裹时没有变化,[email protected]仍然是一个数组,每个参数依然是分割独立的;但当$*被双引号包裹时,SHELL会将所有参数整合为一个字符串。
给脚本文件传递参数
脚本如下:
#!/bin/bash
echo "Process ID: $$"
echo "File Name: $0"
echo "First Parameter : $1"
echo "Second Parameter : $2"
echo "All parameters 1: [email protected]"
echo "All parameters 2: $*"
echo "Total: $#"
输出:
Process ID: 5943
File Name: bash
First Parameter : Shell
Second Parameter : Linux
All parameters 1: Shell Linux
All parameters 2: Shell Linux
Total: 2
边栏推荐
- [untitled]
- [MFC development (16)] tree control
- What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
- factory type_ Id:: create process resolution
- [deep analysis of C language] - data storage in memory
- 明明设计的是高带宽,差点加工成开路?
- The meaning of yolov5 training visualization index
- 《微机原理》——微处理器内部及外部结构
- Advanced API
- 嵌入式工程师常见面试题2-MCU_STM32
猜你喜欢

Share 7 books I read in the first half of 2022

factory type_ Id:: create process resolution

The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies
![Matlab [functions and images]](/img/8a/d2f68b5a7ed396ad20234c0aa24953.jpg)
Matlab [functions and images]

Glitch Free时钟切换技术

公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度

《微机原理》-绪论

1. Connection between Jetson and camera

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?

Audio audiorecord create (I)
随机推荐
MATLAB小技巧(23)矩阵分析--模拟退火
电视机尺寸与观看距离
Only in China! Alicloud container service enters the Forrester leader quadrant
Memory size end
Nacos - 配置管理
C language student information management system
R语言观察日志(part24)--初始化设置
C语言学生信息管理系统
Insert mathematical formula in MD document and mathematical formula in typora
MySQL8.0学习记录17 -Create Table
How to recruit Taobao anchor suitable for your own store
Do you know how data is stored? (C integer and floating point)
Audio audiorecord create (I)
Software Engineer Interview Question brushing website and experience method
Shell脚本-if else语句
爬虫知识点总结
公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度
NFT监管要点和海外政策
长安链同步节点配置与启动
嵌入式工程师面试题3-硬件