返回值127从$是什么意思?在UNIX中。
127返回码$?
回答
如果在PATH
系统变量中找不到给定命令,并且它不是内置shell命令,则返回值为127的/bin/sh
。换句话说,系统不理解你的命令,因为它不知道在哪里找到你想要调用的二进制文件。
它没有特殊的意义,比过去的进程退出与127
但是,它也被用于庆典的退出状态这样做(假设你使用bash作为一个壳)等告诉你你试图执行的命令不能执行(即找不到它)。不幸的是,如果进程退出状态为127,或者无法找到,那么不会立即推论出来。
编辑:
不能立即推论,除了在控制台上的输出,但这是堆栈溢出,所以我假设你在脚本中这样做。
shell约定是成功的可执行文件应该以0值退出。其他任何情况都可以解释为某种类型的故障,或者是您刚刚运行的bash或可执行文件的一部分。另见$ PIPESTATUS和bash的手册页的退出状态部分:
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.
127 - command not found
例如:$ CAAT 错误消息将
bash:
CAAT:找不到命令
现在你检查使用echo $?
非常好的例子! – Victor 2018-02-02 14:57:55
一般它是指:
127 - 找不到
但命令时,它也意味着命令发现,
但是需要命令未找到。
如果您尝试使用脚本语言运行程序,则可能需要包含要执行的文件的完整路径和。例如:
exec('/usr/local/bin/node /usr/local/lib/node_modules/uglifycss/uglifycss in.css > out.css');
谢谢,这对我很有用。所以我做了哪些gs,然后在我的脚本中使用了输出路径。工作.. – Juan 2017-08-02 16:14:56
这个错误也有时候是骗人的。它说,即使文件确实存在,文件也没有找到。这可能是由于您使用的编辑器可能导致文件中存在无效的不可读特殊字符。在这种情况下,这个链接可能会帮助你。
-bash: ./my_script: /bin/bash^M: bad interpreter: No such file or directory
,以找出是否是此问题的最好的办法是简单的地方,在整个文件中的echo语句,如果同样的错误被抛出验证。
- 1. PHP的exec()返回127码
- 2. PHP系统返回127错误代码
- 3. 命令返回非零代码:127
- 4. 使返回错误127
- 5. Proguard的返回错误代码127控制台中看到
- 6. 等待进程ID时返回代码127
- 7. FFmpeg - PHP错误代码127
- 8. Java:InputStream read()返回一个大于127的字节?
- 9. 当没有找到命令时,bash`$?`返回0,而不是127
- 10. maven构建失败返回执行是:'127'
- 11. KSH shell脚本将不会执行并返回127(未找到)
- 12. 无法签署RPM:RPM签名执行返回:'127'
- 13. JQuery返回码
- 14. D3DKMTCreateAllocation返回码
- 15. 返回代码
- 16. 返回码LaunchFullTrustProcessForCurrentAppAsync
- 17. R write_ods函数发回状态127
- 18. 为什么有符号字节的范围是从-128到127(2的补码),而不是从-127到127?
- 19. HttpUtility.HtmlDecode不能解码ASCII超过127
- 20. 非法命令错误代码127
- 21. opentsdb安装过程错误代码127
- 22. WKHTMLTOPDF投掷错误代码127
- 23. NodeJS/Dokku/Docker:ffmpeg用代码127退出
- 24. 调用LoadLibrary()错误代码127
- 25. 返回值与返回错误代码?
- 26. 编码返回值
- 27. Scala的返回码
- 28. PrintReader返回乱码
- 29. sqlldr返回码 - ex_warn
- 30. 返回码误解
如果bash脚本没有模式“+ x”但确实存在,也会发生这种情况。 – MatthewKremer 2014-03-04 20:48:02
您可以尝试使用'which [程序]'来查看操作系统正在使用哪个二进制文件。如果它变空,下一步是检查执行位和PATH。 – cr125rider 2014-06-12 16:33:58
@ cr125rider,''不是特别准确 - 它不知道别名,shell函数,PATH查找记忆或shell状态内部的其他因素。使用'type'更好,这是一个了解所有这些事情的shell内建函数。 – 2014-09-11 22:45:13