Old*_*ool 400
/bin/sh当在PATH系统变量中找不到给定命令且它不是内置shell命令时,返回值127 .换句话说,系统不理解您的命令,因为它不知道在哪里找到您要调用的二进制文件.
小智 9
一个shell约定是一个成功的可执行文件应该以值0退出.任何其他东西都可以被解释为某种类型的失败,部分是bash或刚刚运行的可执行文件.另请参阅bash手册页的$ PIPESTATUS和EXIT STATUS部分:
Run Code Online (Sandbox Code Playgroud)For the shell’s purposes, a command which exits with a zero exit status has succeeded. An exit status of zero indicates success. A non-zero exit status indicates failure. When a command terminates on a fatal signal N, bash uses the value of 128+N as the exit status.
If a command is not found, the child process created to execute it returns a status of 127. If a com-
mand is found but is not executable, the return status is 126.
If a command fails because of an error during expansion or redirection, the exit status is greater than
zero.
Shell builtin commands return a status of 0 (true) if successful, and non-zero (false) if an error
occurs while they execute. All builtins return an exit status of 2 to indicate incorrect usage.
Bash itself returns the exit status of the last command executed, unless a syntax error occurs, in
which case it exits with a non-zero value. See also the exit builtin command below.
Run Code Online (Sandbox Code Playgroud)
它没有特殊意义,除了退出的最后一个进程,退出状态为127.
但是,它也被bash使用(假设您使用bash作为shell)告诉您无法执行您尝试执行的命令(即无法找到它).遗憾的是,如果进程以状态127退出,或者如果找不到,则不能立即进行推理.
编辑:
除了控制台上的输出外,不能立即推导,但这是堆栈溢出,所以我假设你在脚本中这样做.