Linux中shell变量$0,$?等含义

linux中shell变量$#,[email protected],$0,$1,$2的基本含义: 
变量说明: 
$$ 
Shell本身的PID(ProcessID) 
$! 
Shell最后运行的后台Process的PID 
$? 
最后运行的命令的结束代码(返回值) 
$- 
使用Set命令设定的Flag一览 
$* 
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 
[email protected] 
所有参数列表。如"[email protected]"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 
$# 
添加到Shell的参数个数 
$0 
Shell本身的文件名 
$1~$n 
添加到Shell的各参数值。$1是第1参数、$2是第2参数…。

实例:

$ vim dollar.sh

#!/bin/bash
printf "The complete list is %s\n" "$$"
printf "The complete list is %s\n" "$!"
printf "The complete list is %s\n" "$?"
printf "The complete list is %s\n" "$*"
printf "The complete list is %s\n" "[email protected]"
printf "The complete list is %s\n" "$#"
printf "The complete list is %s\n" "$0"
printf "The complete list is %s\n" "$1"
printf "The complete list is %s\n" "$2"
printf "The complete list is %s\n" "$3"

结果展示:

[[email protected] ]$ sh dollar.sh 123456 654321 qq ww
The complete list is 3278
The complete list is
The complete list is 0
The complete list is 123456 654321 qq ww
The complete list is 123456
The complete list is 654321
The complete list is qq
The complete list is ww
The complete list is 4
The complete list is dollar.sh
The complete list is 123456
The complete list is 654321
The complete list is qq
时间: 2024-08-08 04:42:17

Linux中shell变量$0,$?等含义的相关文章

linux中shell变量$#,[email protected],$0,$1,$2的含义解释

摘抄自:ABS_GUIDE 下载地址:http://www.tldp.org/LDP/abs/abs-guide.pdf linux中shell变量$#,[email protected],$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参数列表.如"$*"用「"」括起来的情况.以&qu

【Shell】linux中shell变量$#,[email protected],$0,$1,$2的含义解释 && set 关键字使用

linux中shell变量$#,[email protected],$0,$1,$2的含义解释 摘抄自:ABS_GUIDE 下载地址:http://www.tldp.org/LDP/abs/abs-guide.pdf linux中shell变量$#,[email protected],$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定

【转】linux中shell变量$#,[email protected],$0,$1,$2的含义解释

原文网址:http://www.cnblogs.com/fhefh/archive/2011/04/15/2017613.html linux中shell变量$#,[email protected],$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参数列表.如"$*"用「"」括起来的情况

linux中shell变量$#,[email protected],$0,$1,$2的含义

#!/bin/bash #Created by ley on 2014-11-14 #Testing the Paramters echo  "The compleate list is %s\n" "$$" echo  "The compleate list is %s\n" "$!" echo  "The compleate list is %s\n" "$?" echo  &quo

Linux中shell变量的含义

$# 是传给脚本的参数个数  $0 是脚本本身的名字 $1 是传递给该shell脚本的第一个参数 $2 是传递给该shell脚本的第二个参数 [email protected] 是传给脚本的所有参数的列表 $* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过9个 $$ 是脚本运行的当前进程ID号 $? 是显示最后命令的退出状态,0表示没有错误,其他表示有错误 Linux中shell变量的含义

浅谈linux中shell变量$#,[email protected],$0,$1,$2,$?的含义解释

浅谈linux中shell变量$#,[email protected],$0,$1,$2,$?的含义解释 下面小编就为大家带来一篇浅谈linux中shell变量$#,[email protected],$0,$1,$2的含义解释.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 摘抄自:ABS_GUIDE 下载地址:http://www.tldp.org/LDP/abs/abs-guide.pdf linux中shell变量$#,[email protected],$

linux中的$0 S# $*……的含义

$0 这个程式的执行名字 $n 这个程式的第n个参数值,n=1..9 $* 这个程式的所有参数,此选项参数可超过9个. $# 这个程式的参数个数 $$ 这个程式的PID(脚本运行的当前号) $! 执行上一个背景指令的PID(后台运行的最后一个进程的号) $? 执行上一个指令的返回值 (显示最后命令的退出状态.0表示没有错误,其他任何值表明有错误) $- 显示shell使用的当前选项,与set命令功能相同 [email protected] 跟$*类似,但是可以当作数组用 linux中shell变

linux中shell脚本的学习(一)

linux中shell是一个特殊的应用程序.它介于系统的内核与用户之间.充当命令"解释器"的作用角色.负责接收用户输入的操作指令,并进行解释.将需要执行的操作传递给内核.并输出执行结果: 下面我们来看一下当前系统所支持的shell的种类: 其中/bin/shell 是目前大多数linux中采用的默认shell.我们主要学习bash. 我们来写第一个脚本文件用作测试. vim first.sh cd /boot/ pwd ls -lh * chmod +x first.sh shell脚

linux中shell编程

shell编程 1 echo -e 识别\转义符 \a \b \t \n \x十六进制 \0八进制 等等 #!/bin/bash echo -e "hello world" 执行脚本:方式1 :chmod 755 hello.sh ./hello.sh 方式2 :bash ./hello.sh(这种方式不需要给执行权限) 1 历史命令 history 直接回车就可以看到已经敲过得命令.-c清空缓存中和文件中的命令 -w将缓存中命令写入 家目录/.bash_history 这个命令可以帮