shell 脚本之特殊变量字符
2016-11-30 09:45
573 查看
shell 脚本之特殊变量字符
shell 脚本中我们知道变量都是以$符号开头的,但是有一些特殊的变量也很有用,这里我们就介绍一下有哪些比较实用的。$0 这个脚本的执行名字 -------------------------- #! /bin/bash echo $0 -------------------------- [root@localhost performance]# ./test.sh ./test.sh
$n 这个程式的第n个参数值,n=1..9 ----------------------------------------- [root@localhost performance]# cat test.sh #! /bin/bash echo $1 $2 $3 ----------------------------------------- [root@localhost performance]# ./test.sh hello world 123 hello world 123
$* 这个程式的所有参数,此选项参数可超过9个。 (所有参数组成一个字符串) ---------------------------------------------------------- #! /bin/bash echo $* ---------------------------------------------------------- [root@localhost performance]# ./test.sh I love shell I love shell
$@ 跟$*类似,但是可以当作数组用 (返回多个参数字符串) ------------------------------------------------ #! /bin/bash echo $@ ------------------------------ [root@localhost performance]# ./test.sh I love shell I love shell
$# 这个程式的参数个数 ------------------ #! /bin/bash echo $# ------------------ [root@localhost performance]# ./test.sh I love shell 3
$? 执行上一个指令的返回值 (显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误) ------------------------------------------------ #! /bin/bash cd abc #打开不存在目录 echo $? cd ./ #打开当前目录 echo $? ------------------------------ [root@localhost performance]# ./test.sh ./test.sh: line 2: cd: abc: No such file or directory 1 0
$$ 这个程式的PID(脚本运行的当前进程ID号) ----------------------------------- #! /bin/bash echo $$ ----------------------------------- [root@localhost performance]# ./test.sh I love shell 22508
$! 执行上一个背景指令的PID(后台运行的最后一个进程的进程ID号) $- 显示shell使用的当前选项,与set命令功能相同
相关文章推荐
- Shell脚本中的位置变量参数(特殊字符)实例讲解
- Shell脚本中的位置变量参数(特殊字符)实例讲解
- shell脚本变量特殊字符的含义
- Shell变量名使用的特殊字符
- [Linux] shell bash 脚本特殊变量 [大三TJB_708]
- shell脚本中28个特殊字符的作用简明总结
- Shell变量名使用的特殊字符 [转]
- Shell脚本常识--(特殊字符)
- Shell变量名使用的特殊字符
- shell脚本中的特殊变量
- shell脚本之变量、变量类型、条件测试、算术运算、及特殊变量
- shell脚本中一些特殊字符
- shell 脚本中的特殊变量 以及 shell 脚本的调试
- sed命令 shell变量 特殊字符
- shell脚本中28个特殊字符的作用简明总结
- shell脚本学习:特殊变量和C语言格式循环
- shell 知识点补充(1)-提示字符的设定/read/declare / typeset/变量设定功能/别名/万用字符与特殊符号
- shell脚本及makefile中的特殊变量
- shell 笔记 特殊变量 特殊字符 Metacharacters
- [置顶] shell脚本的特殊字符