Linux shell 变量$#,$@,$0....的含义

1 $#:传入的参数数量 
2 $@:传入的参数列表
3 $*:传入的参数
4 $0:Shell本身的文件名
5 $1,$2...:传入的第 i 个参数
6 $?:上一条命令返回的状态码
7 $!:Shell 最后运行的后台 Process 的 PID
8 $$:Shell本身自己的PID

 实例

 1 #!/bin/bash
 2 #
 3 printf "The complete list is %s\n" "$$"
 4 printf "The complete list is %s\n" "$!"
 5 printf "The complete list is %s\n" "$?"
 6 printf "The complete list is %s\n" "$*"
 7 printf "The complete list is %s\n" "$@"
 8 printf "The complete list is %s\n" "$#"
 9 printf "The complete list is %s\n" "$0"
10 printf "The complete list is %s\n" "$1"
11 printf "The complete list is %s\n" "$2

结果

 1 [Aric@localhost ~]$ bash params.sh 123456 QQ
 2 The complete list is 24249
 3 The complete list is
 4 The complete list is 0
 5 The complete list is 123456 QQ
 6 The complete list is 123456
 7 The complete list is QQ
 8 The complete list is 2
 9 The complete list is params.sh
10 The complete list is 123456
11 The complete list is QQ

 

posted @ 2020-10-05 22:42  HEREISDAVID  阅读(1069)  评论(0编辑  收藏  举报