Shell中$#、$0、set等的含义
Shell脚本变量$#,$*等的含义
$# # 表示执行脚本传入参数的个数
$* # 表示执行脚本传入参数的列表(不包括$0)
$$ # 表示进程的id
$@ # 表示执行脚本传入参数的所有个数(不包括$0)
$0 # 表示执行的脚本名称
$1 # 表示第一个参数
$? # 表示脚本执行的状态,0表示正常,其他表示错误#!/usr/bin/env bash
printf "the process id is %s\n" "$$" # 进程ID
printf "the return value is %s\n" "$?" # 脚本返回值
printf "the all argus is %s\n" "$*" # 传入的参数列表
printf "the argus is %s\n" "$@" # 循环输出传入的参数
printf "the number of argus is %s\n" "$#" # 传入参数的数量
printf "the first argus0 is %s\n" "$0" # 当前执行的脚本名字
printf "the argus 1 is %s\n" "$1" # 输出传入第一个参数
printf "the argus 2 is %s\n" "$2" # 输出传入第二个参数$*和$@的差异
显示所有环境变量
脚本常用set命令
Last updated