What is the meaning of return value 127 from $? in UNIX.
相关问题
- how to get running process information in java?
- Stop child process when parent process stops
- Program doesn’t terminate when using processes
- Why should we check WIFEXITED after wait in order
- UNIX Bash - Removing double quotes from specific s
相关文章
- Making new files automatically executable?
- Reverse four length of letters with sed in unix
- How to start a process in its own process group?
- Extracting columns from text file using Perl one-l
- Problem with piping commands in C
- How to redirect child process stdout/stderr to the
- Makefile and use of $$
- File locked by which process?
Value 127 is returned by
/bin/sh
when the given command is not found within yourPATH
system variable and it is not a built-in shell command. In other words, the system doesn't understand your command, because it doesn't know where to find the binary you're trying to call.If you're trying to run a program using a scripting language, you may need to include the full path of the scripting language and the file to execute. For example:
Generally it means:
127 - command not found
but it can also mean that the command is found,
but a library that is required by the command is NOT found.
A shell convention is that a successful executable should exit with the value 0. Anything else can be interpreted as a failure of some sort, on part of bash or the executable you that just ran. See also $PIPESTATUS and the EXIT STATUS section of the bash man page:
It has no special meaning, other than that the last process to exit did so with an exit status of 127.
However, it is also used by bash (assuming you're using bash as a shell) to tell you that the command you tried to execute couldn't be executed (i.e. it couldn't be found). It's unfortunately not immediately deducible though, if the process exited with status 127, or if it couldn't found.
EDIT:
Not immediately deducible, except for the output on the console, but this is stack overflow, so I assume you're doing this in a script.
This error is also at times deceiving. It says file is not found even though the files is indeed present. It could be because of invalid unreadable special characters present in the files that could be caused by the editor you are using. This link might help you in such cases.
-bash: ./my_script: /bin/bash^M: bad interpreter: No such file or directory
The best way to find out if it is this issue is to simple place an echo statement in the entire file and verify if the same error is thrown.