关于$?

来源:互联网 发布:网络维护如何收费 编辑:程序博客网 时间:2024/06/12 00:57

其实就是上一次程序或脚本的退出码,主要是用来判断程序或脚本的执行是否成功,检查出错的原因之类的.

这是SHELL的一部分,一般情况下,在linux/unix下编程时,我们会在应用程序退出时返回一个整型数据(在main函数中通过return/exit,或者别的函数/方法中exit)。这个返回值是给SHELL使用的,因为我们可能需要了解应用程序的执行状态,然后根据不同的执行状态去执行不同的分支(类似于函数的返回值)。

and more....

$n        $1 the first parameter,$2 the second...
$#        The number of command-line parameters.
$0        The name of current program.
$?        Last command or function's return value.
$$        The program's PID.
$!        Last program's PID.
$@        Save all the parameters.

almost any shell book will talk about them,from which you can get their detail usages


0 0