当前位置:网站首页>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
边栏推荐
- 【js逆向】md5加密参数破解
- C语言指针的进阶(上篇)
- Shell脚本-位置参数(命令行参数)
- Intelligent water supply system solution
- 性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
- Only in China! Alicloud container service enters the Forrester leader quadrant
- 长安链同步节点配置与启动
- 如何一站式高效管理固定资产?
- 《MATLAB 神经网络43个案例分析》:第30章 基于随机森林思想的组合分类器设计——乳腺癌诊断
- 【C】 Summary of wrong questions in winter vacation
猜你喜欢

1. Connection between Jetson and camera

MATLAB【函数求导】

基础:2.图像的本质

Brief introduction to AES

Agrometeorological environment monitoring system

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

Only in China! Alicloud container service enters the Forrester leader quadrant

电脑小技巧

Huawei machine test questions column subscription Guide

MAVROS发送自定义话题消息给PX4
随机推荐
There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
我想知道手机注册股票开户的流程?另外,手机开户安全么?
Shell脚本-echo命令 转义符
Redis源码学习(29),压缩列表学习,ziplist.c(二)
Differences among tasks, threads and processes
Do you know how data is stored? (C integer and floating point)
集团公司固定资产管理的痛点和解决方案
【面试必刷101】链表
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
电视机尺寸与观看距离
Glitch Free时钟切换技术
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?
Brief introduction to AES
Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
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
SPL installation and basic use (II)
TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
Nacos - service discovery
What is the material of 15CrMoR, mechanical properties and chemical analysis of 15CrMoR
Model and view of QT