返回值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. 命令返回非零代碼:127
- 3. Docker構建 - 返回非零代碼:127
- 4. PHP系統返回127錯誤代碼
- 5. 使返回錯誤127
- 6. 等待進程ID時返回代碼127
- 7. Proguard的返回錯誤代碼127控制檯中看到
- 8. 在PHP執行命令返回錯誤代碼127
- 9. FFmpeg - PHP錯誤代碼127
- 10. Python subprocess.CalledProcessError:命令'adb設備'返回非零退出狀態127
- 11. 使用vim latex-suite查看pdf:!start預覽shell返回127
- 12. 螞蟻rebuilddb命令失敗 - 執行返回:127
- 13. KSH shell腳本將不會執行並返回127(未找到)
- 14. 由altbeacon函數庫返回的rssi 127提高了距離
- 15. 從cron腳本寫入crontab返回127錯誤
- 16. 子呼叫,將返回127提供的完整路徑
- 17. Java:InputStream read()返回一個大於127的字節?
- 18. 當沒有找到命令時,bash`$?`返回0,而不是127
- 19. maven構建失敗返回執行是:'127'
- 20. sys.exit默認區間之外返回值[0-127]
- 21. btowc(c)總是返回(c在0..127?c:WEOF)嗎?
- 22. 在ec2上安裝npm會返回127錯誤
- 23. 無法簽署RPM:RPM簽名執行返回:'127'
- 24. GetLastError 127
- 25. D3DKMTCreateAllocation返回碼
- 26. JQuery返回碼
- 27. 返回碼LaunchFullTrustProcessForCurrentAppAsync
- 28. osx:ld返回碼
- 29. 返回代碼
- 30. 的Android SQLite的最大回報127
如果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