当前位置:网站首页>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
边栏推荐
- MATLAB【函数和图像】
- Principle and application of single chip microcomputer - off chip development
- Review of week 280 of leetcode
- Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
- 避免按钮重复点击的小工具bimianchongfu.queren()
- MATLAB小技巧(23)矩阵分析--模拟退火
- Memory size end
- View drawing process analysis
- Vscode customize the color of each area
- Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates
猜你喜欢

避免按钮重复点击的小工具bimianchongfu.queren()

Do you know how data is stored? (C integer and floating point)

Nacos - gestion de la configuration

FreeRTOS学习简易笔记

Screenshot tips

Bimianhongfu queren()

Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting

《单片机原理及应用》—定时器、串行通信和中断系统
![[untitled]](/img/40/560c597d53d27eff860644cd7c3030.png)
[untitled]

【MFC开发(16)】树形控件Tree Control
随机推荐
[deep analysis of C language] - data storage in memory
你了解数据是如何存储的吗?(C整型和浮点型两类)
yolov5训练可视化指标的含义
Nacos - 配置管理
Qt的模型与视图
电脑小技巧
MySQL8.0学习记录17 -Create Table
How can enterprises and developers take the lead in the outbreak of cloud native landing?
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code
Matlab [function derivation]
DataBinding源码分析
I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
3、Modbus通讯协议详解
VSYNC+三重缓存机制+Choreographer
又到年中,固定资产管理该何去何从?
Vscode customize the color of each area
[untitled]
目标检测的yolov3、4、5、6总结
Shell脚本-for循环和for int循环
Internet of things technology is widely used to promote intelligent water automation management