当前位置:网站首页>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
边栏推荐
- 任务、线程、进程 区别
- 【MFC开发(16)】树形控件Tree Control
- 又到年中,固定资产管理该何去何从?
- Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
- 你了解数据是如何存储的吗?(C整型和浮点型两类)
- 基础:2.图像的本质
- 日常办公耗材管理解决方案
- 3、Modbus通讯协议详解
- Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
- Foundation: 2 The essence of image
猜你喜欢

【无标题】

Internet of things technology is widely used to promote intelligent water automation management

内存大小端

Insert mathematical formula in MD document and mathematical formula in typora

你了解数据是如何存储的吗?(C整型和浮点型两类)

There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way

《MATLAB 神经网络43个案例分析》:第30章 基于随机森林思想的组合分类器设计——乳腺癌诊断

Matlab tips (23) matrix analysis -- simulated annealing

How can enterprises and developers take the lead in the outbreak of cloud native landing?

C语言指针的进阶(上篇)
随机推荐
串口转WIFI模块通信
Brief introduction to AES
基础:3.opencv快速入门图像和视频
电脑小技巧
factory type_ Id:: create process resolution
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
Internet of things technology is widely used to promote intelligent water automation management
Centos7 shell脚本一键安装jdk、mongo、kafka、ftp、postgresql、postgis、pgrouting
Shell脚本-echo命令 转义符
Qt的模型与视图
如何做好固定资产管理?易点易动提供智能化方案
嵌入式工程师面试题3-硬件
Only in China! Alicloud container service enters the Forrester leader quadrant
固定资产管理系统让企业动态掌握资产情况
3. Detailed explanation of Modbus communication protocol
电视机尺寸与观看距离
vscode自定义各个区域的颜色
Nacos - 配置管理
中小企业固定资产管理办法哪种好?
The data analyst will be ruined without project experience. These 8 project resources will not be taken away