当前位置:网站首页>Shell script - special variables: shell $, $*, [email protected], $$$
Shell script - special variables: shell $, $*, [email protected], $$$
2022-07-01 08:47:00 【Little snail's way】
| Variable | meaning |
|---|---|
| $0 | File name of the current script . |
| $n(n≥1) | Parameters passed to a script or function .n It's a number , Indicates the number of parameters . for example , The first parameter is $1, The second parameter is $2. |
| $# | Number of arguments passed to script or function . |
| $* | All parameters passed to a script or function . |
| [email protected] | All parameters passed to a script or function . When double quotes " " Inclusion time ,[email protected] And $* not quite the same |
| $? | Exit status of last command , Or the return value of the function |
| $$ | At present Shell process ID. about Shell Script , It's the process of these scripts ID. |
$* And [email protected] Difference : When wrapped in double quotation marks ,[email protected] There is no change when it is not wrapped in double quotation marks ,[email protected] It's still an array , Each parameter is still separate ; But when $* When wrapped in double quotation marks ,SHELL All parameters will be integrated into one string .
Pass parameters to the script file
The script is as follows :
#!/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: $#"
Output :
Process ID: 5943
File Name: bash
First Parameter : Shell
Second Parameter : Linux
All parameters 1: Shell Linux
All parameters 2: Shell Linux
Total: 2
边栏推荐
猜你喜欢

分享2022上半年我读过的7本书

factory type_ Id:: create process resolution

3、Modbus通讯协议详解

AVL树的理解和实现

Principle and application of single chip microcomputer - principle of parallel IO port

vscode自定义各个区域的颜色

集团公司固定资产管理的痛点和解决方案

Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling

Matlab tips (23) matrix analysis -- simulated annealing

《微机原理》-绪论
随机推荐
Nacos - service discovery
又到年中,固定资产管理该何去何从?
Advanced C language pointer (Part 2)
Do you know how data is stored? (C integer and floating point)
1.jetson与摄像头的对接
《微机原理》—总线及其形成
嵌入式工程师常见面试题2-MCU_STM32
基础:3.opencv快速入门图像和视频
Matlab [function derivation]
Introduction to R language
Software Engineer Interview Question brushing website and experience method
Shell脚本-位置参数(命令行参数)
【C】 Summary of wrong questions in winter vacation
Shell脚本-for循环和for int循环
如何解决固定资产管理和盘点的难题?
Shell脚本-select in循环
How can enterprises and developers take the lead in the outbreak of cloud native landing?
挖财打新股安全吗
factory type_ Id:: create process resolution
毕业季,我想对你说