我知道,要查看我们最后执行的命令是否正确是 shell,我们使用“echo $?
”命令。
为什么它返回 2 作为输出,这意味着什么?
最佳答案
您应该关注 echo $? 之前的最后一个命令。打开该命令手册页。您可以找到退出代码的含义。
例如;
man grep;
...
EXIT STATUS
The exit status is 0 if selected lines are found, and 1 if not found.
If an error occurred the exit status is 2.
(Note: POSIX error handling code should check for '2' or greater.)
....
或
man ls;
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
或
man diff
Exit status is 0 if inputs are
the same, 1 if different, 2 if trouble.
关于linux - 如果 "echo $?"命令返回 2 怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40233175/