Linux中$?是什么意思?

bonny95 2008-09-22 10:04:56
最近在看Linux Shell,一直搞不懂$?是什么,请高手赐教。拜谢!
...全文
64258 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
踏岸寻柳 2008-09-24
  • 打赏
  • 举报
回复
这是SHELL的一部分,意思上面有提及。
一般情况下,在linux/unix下编程时,我们会在应用程序退出时返回一个整型数据(在main函数中通过return/exit,或者别的函数/方法中exit)。这个返回值是给SHELL使用的,因为我们可能需要了解应用程序的执行状态,然后根据不同的执行状态去执行不同的分支(类似于函数的返回值)。
realdragon2 2008-09-23
  • 打赏
  • 举报
回复
呵呵,赞.
fox000002 2008-09-23
  • 打赏
  • 举报
回复
其实就是上一次程序或脚本的退出码,主要是用来判断程序或脚本的执行是否成功,检查出错的原因之类的
leeyiqun 2008-09-23
  • 打赏
  • 举报
回复
呵呵,就是上一次命令的退出状态。成功值为0,不成功为非0!
csan 2008-09-23
  • 打赏
  • 举报
回复
$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.
cceczjxy 2008-09-23
  • 打赏
  • 举报
回复
获取进程的退出状态及接收的信号值。
weidong0210 2008-09-23
  • 打赏
  • 举报
回复
up
huoyin 2008-09-22
  • 打赏
  • 举报
回复
$?表示上一次程序退出值,你可以自己写一个1.sh脚本如下:
exit 2

然后在命令行下执行该脚本,最后在shell中输入echo $?看看效果
iasky 2008-09-22
  • 打赏
  • 举报
回复
Before we move on, there is a perversity about tests in Bash shells that I want to discuss. It turns out, because of a historical accident that now might as well be cast in concrete, when a test is conducted or a command returns a result value, the numerical value for "true" is 0, and "false" is 1. Those of you who have some programming experience will likely find this reversal of intuition as annoying as I do.

Here is a way to get the result of the most recent logical test (and to show the weird reversal described above):

$ test -e .
$ echo $?
0

$ test -e xyz
$ echo $?
1

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧