Shell - Shell script to pass parameters

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_15071263/article/details/102753942

Shell - Shell script to pass parameters


1, parameter passing rules

Separated by a space.

./xxx.sh 1 2 3

2, the parameter reference rule

$ N to the n-th reference parameter, n starting from 1

echo "param 1 : $1"
echo "param 2 : $2"
echo "param 3 : $3"

3, the implementation of file parameters

$ 0 is passed executable file name

echo "x file name : $0"

4, to obtain the number of parameters passed

echo "param count : $#"

5, other combinations of special

## 显示所有的参数为一个字符串
echo "$*"

## 显示当前脚本运行的进程ID
echo $$

## 显示后台运行的最后一个进程的ID
echo $!

## 显示所有的参数为单个的字符串
echo "$@"

## 显示shell 使用的当前选项
echo $-

## 显示命令的退出状态,0表示没有错误,其它值表明有错误
echo $?

Guess you like

Origin blog.csdn.net/qq_15071263/article/details/102753942