NotePublic/Software/System/Linux/Modules/Shell/Linux_中在终端捕获程序的返回值.md

12 lines
480 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Linux 中在终端捕获程序的返回值
在程序运行结束后在终端shell 界面)上输入命令:
```bash
echo $?
```
显示的即为上一个程序结束时的返回值return 1exit2_exit12都可以abort 退出时,返回值为随机数)。
功能:可以判断上一个程序时在什么情况下结束的。正常情况下,返回值为 0 即为正常退出;为 1 或 -1 为错误终止退出,也可以自己设置值。