@ghostfn1
2016-03-06T07:04:39.000000Z
字数 734
阅读 2208
Shell Linux
Update Time:160306 Sunday
Linux Shell下的预定义变量,是指由系统保留和维护的一组特殊的变量,这些变量通常用于保存程序运行状态等。预定义变量由系统自动生成和维护,用户无需修改其值。常见的有:
$?最后一次执行的命令的返回状态。如果这个变量的值为0,证明上一个命令正确执行;如果这个变量的值为非0(具体是哪个数,由命令自己来决定),则证明上一个命令执行不正确了。如:[root@localhost test]# sdlasdbash: sdlasd: command not found[root@localhost test]# $?bash: 127: command not found[root@localhost test]# ls dshdsls: cannot access dshds: No such file or directory[root@localhost test]# $?bash: 2: command not found$!后台运行的最后一个进程的进程号(PID)如:#!/bin/bash# Author: shenchao (E-mail: shenchao@lampbrother.net)echo "The current process is $$"# output the PID, that is, the PID when runs variable.shfind /root -name hello.sh &# find hello.sh file in root dir.echo "The last one Daemon process is $!"$$当前进程的进程号(PID)$0保存当前程序或脚本的名称$*保存传递给脚本或进程的所有参数$#用于保存脚本的参数个数