bash `ls` 退出状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1010939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
`ls` exit status
提问by Alex S
EDIT: nothing to see here!!! 127 return means the command wasn't found - had to give an absolute path to the command for some reason :/ (I didn't delete in case someone else has this problem)
编辑:这里没什么可看的!!!127 返回意味着未找到该命令 - 由于某种原因必须给出该命令的绝对路径:/(我没有删除以防其他人遇到此问题)
Is there a reference of return statuses for common Linux functions like ls? (it doesn't seem to be in the man pages, at least for ls). If not, can someone tell me what lsreturning 127 means?
是否有常见 Linux 功能的返回状态参考,例如ls?(它似乎不在手册页中,至少对于ls)。如果没有,谁能告诉我ls返回 127 是什么意思?
采纳答案by Alex S
127 is the error for command not found. In this case, I just had to use an absolute path to the command (/bin/ls)
127 是找不到命令的错误。在这种情况下,我只需要使用命令的绝对路径 ( /bin/ls)
回答by Earlz
as per http://www.opengroup.org/onlinepubs/009695399/utilities/ls.htmla return value of 0 means success, anything >0 is an error
根据http://www.opengroup.org/onlinepubs/009695399/utilities/ls.html返回值 0 表示成功,任何 >0 都是错误
回答by Sinan ünür
lsis not a Bash function. It is an external utility. On Linux, lsis part of the GNU File Utilities. man lsshould show you similar information as http://www.gnu.org/software/coreutils/manual/html_node/ls-invocation.htmlwhere the only possible values for its exit status are defined as 0, 1 and 2.
ls不是 Bash 函数。它是一个外部实用程序。在 Linux 上,ls是 GNU 文件实用程序的一部分。man ls应该向您显示与http://www.gnu.org/software/coreutils/manual/html_node/ls-invocation.html类似的信息,其中退出状态的唯一可能值定义为 0、1 和 2。
回答by Jeffrey Kemp
for ls: "Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble."
对于 ls:“退出状态为 0 表示正常,1 表示小问题,2 表示严重问题。”
Source: UNIX man pages : ls
来源:UNIX 手册页:ls
I suspect your options to find this out generally are:
我怀疑您的选择通常是:
- man
- source code analysis
- 男人
- 谷歌
- 源代码分析

