当前位置:网站首页>Shell script - positional parameters (command line parameters)
Shell script - positional parameters (command line parameters)
2022-07-01 08:47:00 【Little snail's way】
function Shell We can pass some parameters to the script file , These parameters can be used inside the script file $n To receive , for example ,$1 Represents the first parameter ,$2 Represents the second parameter , By analogy .
Pass location parameters to the script file
The script is as follows :
#!/bin/bash
echo "name: $1"
echo "age: $2"
Carry out orders :sh test.sh jack 18, among jack Is the first positional parameter ,18 Is the second position parameter , The two are separated by spaces . Output is as follows :
name: jack
age: 18
Passing positional parameters to a function
The script is as follows :
#!/bin/bash
# Defined function
function func(){
echo "name: $1"
echo "age: $2"
}
# Call function
func jack 20
Output :
name: jack
age: 20
matters needing attention
If there are too many parameters , Reach or exceed 10 individual , Then we have to use ${n} To receive , for example ${10}、${23}.{ } The function of is to help the interpreter identify the boundary of parameters , This is the same as adding... When using variables { } It's the same effect .
边栏推荐
- The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies
- 19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
- Software Engineer Interview Question brushing website and experience method
- Computer tips
- 固定资产管理系统让企业动态掌握资产情况
- Serial port to WiFi module communication
- View drawing process analysis
- Qt的模型与视图
- Only in China! Alicloud container service enters the Forrester leader quadrant
- C language student information management system
猜你喜欢

Personal decoration notes

Matlab tips (23) matrix analysis -- simulated annealing

The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies

Audio audiorecord create (I)

《微机原理》—总线及其形成

安装Oracle EE

Insert mathematical formula in MD document and mathematical formula in typora

Bimianhongfu queren()

大型工厂设备管理痛点和解决方案

Vscode customize the color of each area
随机推荐
《微机原理》—总线及其形成
LogBack
个人装修笔记
Qt的模型与视图
[deep analysis of C language] - data storage in memory
又到年中,固定资产管理该何去何从?
Configuration and startup of Chang'an chain synchronization node
Shell脚本-case in 和正则表达式
固定资产管理系统让企业动态掌握资产情况
JCL 和 SLF4J
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
Audio audiorecord create (I)
避免按钮重复点击的小工具bimianchongfu.queren()
Audio-AudioRecord create(一)
Nacos - 配置管理
Glitch Free时钟切换技术
FreeRTOS learning easy notes
串口转WIFI模块通信