What is the meaning of return value 127 from $? in UNIX.
asked Nov 19, 2009 at 13:05
Sachin ChourasiyaSachin Chourasiya
20.6k32 gold badges86 silver badges98 bronze badges
Value 127 is returned by /bin/sh when the given command is not found within your PATH 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.
answered Nov 19, 2009 at 13:08
7
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.
answered Jul 23, 2013 at 21:34
okiganokigan
1,5392 gold badges18 silver badges33 bronze badges
0
127 - command not found
example: $caat
The error message will
bash:
caat: command not found
now you check using echo $?
Victor
3,8322 gold badges35 silver badges63 bronze badges
answered Oct 15, 2012 at 11:25
Anitha ManiAnitha Mani
8631 gold badge9 silver badges17 bronze badges
0
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:
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.
answered Nov 19, 2009 at 13:25
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.
answered Nov 19, 2009 at 13:07
falstrofalstro
34.4k9 gold badges72 silver badges86 bronze badges
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:
exec('/usr/local/bin/node /usr/local/lib/node_modules/uglifycss/uglifycss in.css > out.css');
answered Feb 12, 2017 at 22:41
NickNick
10.8k10 gold badges48 silver badges78 bronze badges
1
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.
answered Sep 14, 2017 at 13:48
If the IBM mainframe JCL has some extra characters or numbers at the end of the name of unix script being called then it can throw such error.
answered Jun 11, 2019 at 20:21
Smart CoderSmart Coder
1,28516 silver badges18 bronze badges
In addition to the given answers, note that running a script file with incorrect end-of-line characters could also result in 127 exit code if you use /bin/sh as your shell.
As an example, if you run a shell script with CRLF end-of-line characters in a UNIX-based system and in the /bin/sh shell, it is possible to encounter some errors like the following I’ve got after running my script named my_test.sh :
$ ./my_test.sh
sh: 2: ./my_test.sh: not found
$ echo $?
127
As a note, using /bin/bash, I got 126 exit code, which is in accordance with gnu.org documentation about the bash :
If a command is not found, the child process created to execute it returns a status of
127. If a command is found but is not executable, the return status is126.
Finally, here is the result of running my script in /bin/bash :
arman@Debian-1100:~$ ./my_test.sh
-bash: ./my_test.sh: /bin/bash^M: bad interpreter: No such file or directory
arman@Debian-1100:~$ echo $?
126
answered Apr 26, 2022 at 16:19
- go to C:Program FilesGitetc
- open gitconfig with notepad
- change
[core]
autocrlf = true
To
[core]
autocrlf = false
answered Aug 8, 2022 at 10:16
���������� C. ���� ����������, �������
���������������� �����
������� C-1. «�����������������» ����
����������
| ��� ���������� | ����� | ������ | ���������� |
|---|---|---|---|
| 1 | ������������� ������ | let «var1 = 1/0» | ��������� ������, ����� ��� «������� �� ����» � ��. |
| 2 | �������� ������������ � Bash — �������� ������������� ���������� ������ |
� | ����������� �������� �����, ������ ��� ���������� ������������ ������ 1 |
| 126 | ���������� ������� �� ����� ���� ��������� |
� | ��������� ��-�� ������� � ������� ������� ��� ����� ������ �� ���������� ������������� ���� |
| 127 | «������� �� �������» | � | �������� ������� ���� � ���������� ��������� $PATH, ���� � �������� ���������� ����� ������� |
| 128 | �������� �������� ������� exit | exit 3.14159 | ������� exit ����� ��������� ������ ������������� ��������, � ��������� 0 — 255 |
| 128+n | ��������� ������ �� ������� «n» | kill -9 $PPID �������� | $? ������ 137 (128 + 9) |
| 130 | ���������� �� Control-C | � | Control-C — ��� ����� �� ������� 2, (130 = 128 + 2, ��. ����) |
| 255* | ��� ���������� ��� ����������� ��������� |
exit -1 | exit ����� ��������� ������ ������������� ��������, � ��������� 0 — 255 |
�������� ���� �������, ���� ���������� 1 — 2, 126 — 165 � 255
[1] ����� ���������������� ��������,
������� ��� ������� �������� ������������ ���� ����� ��� �����
����. ���������� �������� � ����� �������� exit 127, ����� �������� �
�������������� ��� ������ ������ � �������� (������������� �� ��
�������� ������ «������� �� �������»? ��� ���
��������������� ������������� ��� ����������?). � �����������
�������, ������������ ��������� exit 1, � �������� ������� �� ������.
��� ��� ��� ���������� 1 ������������� �����
«�����» ������, �� � ������ ������ ������ �������� �
����� ���� ���������������, ���� � �� ��������������� —
����.
�� ��� ��������������� ������� ����������������� ����
���������� (��. /usr/include/sysexits.h), �� ���
�������������� ������������� ��� �������������, ������� �� ������
C � C++. ����� ��������� ���������� ���������� ���� ����������,
������������ �������������, ���������� 64 — 113 (�, ���� �����
���������� — 0, ��� ����������� ��������� ����������), �
������������ �� ���������� C/C++. ��� ������� �� ����� ������
����� �������.
��� ��������, ����������� � ������� ���������, ��������� �
������������ � ���� ����������, �� ����������� �������, �����
���������� ���������� ��������������, �������� � ������ 9-2.
![]() |
��������� � ���������� $?, �� ��������� |
I attempted to follow this guide to run a Node application as a service. However, it is failing to start, with exit code 127. Is there any way to fix this?
This is the journal.
sudo journalctl --follow -u serviceName
-- Logs begin at Tue 2017-08-08 16:27:10 GMT. --
Aug 08 17:06:57 raspberrypi systemd[1]: Started serviceName.
Aug 08 17:06:57 raspberrypi app.js[7234]: [46B blob data]
Aug 08 17:06:57 raspberrypi systemd[1]: serviceName.service: main process exited, code=exited, status=127/n/a
Aug 08 17:06:57 raspberrypi systemd[1]: Unit serviceName.service entered failed state.
Aug 08 17:06:57 raspberrypi systemd[1]: serviceName.service holdoff time over, scheduling restart.
Aug 08 17:06:57 raspberrypi systemd[1]: Stopping serviceName...
Aug 08 17:06:57 raspberrypi systemd[1]: Starting serviceName...
Aug 08 17:06:57 raspberrypi systemd[1]: serviceName.service start request repeated too quickly, refusing to start.
Aug 08 17:06:57 raspberrypi systemd[1]: Failed to start serviceName.
Aug 08 17:06:57 raspberrypi systemd[1]: Unit serviceName.service entered failed state.
This is the serviceName.service.
[Unit]
Description=ServiceName
After=network.target
[Service]
ExecStart=/home/pi/projects/ServiceName/app.js
Restart=always
User=root
Group=root
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/home/pi/projects/ServiceName
[Install]
WantedBy=multi-user.target
This is at the top of my app.js.
#!/usr/bin/env node
i wrote some scrip for setting route on specific interface on linux (CentOS 6.0)
and put them into Networkmanager script path (/etc/Networkmanager/dispatcher.d)
with highest prefix number.(i give execution permition too.)
this is my script:
#!/bin/bash
if [[ "$1" == "eth1" ]] && [[ "$2" == "up" ]]
then
ip route add 192.XX.XX.0/24 dev eth1 src 192.XX.XX.XX table eth1
#logger scrip run.
fi
but when eth1 is up i see this error on my syslog-message list:
localhost nm-dispatcher.action: Script '/etc/NetworkManager/dispatcher.d/99-eth' exited with error status 127.
can anyone say where is my mistake??
Comments
Issue Type: Bug
Whenever i’m running a debug configuration on a remote Linux host, i get the following error:
The terminal process "bash ''" failed to launch (exit code: 127).
This started happening after today’s update.
Extension version: 1.4.0-insiders2
VS Code version: Code — Insiders 1.57.0-insider (a9c5e37ea0dc020f5df3b1c82ef020627fc8cd7c, 2021-05-19T08:54:56.348Z)
OS version: Windows_NT x64 10.0.18363
Remote OS version: Linux x64 5.8.7
Remote OS version: Linux x64 5.4.0-56-generic
Remote OS version: Linux x64 5.4.0-56-generic
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
pythonvspyt602:30291494
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30291487
pythontb:30258533
pythonvspyt551:30291412
vspre833cf:30267465
pythonptprofiler:30281269
vshan820:30294714
pythondataviewer:30285072
vscus158:30286553
pythonvsuse255:30303025
vscorehov:30301224
vscod805cf:30301675
Does changing C_Cpp.updateChannel to «Default» and having it revert to 1.3.1 fix the issue? Or is this an issue with VS Code Insiders updating? 1.4.0-insiders2 didn’t have any debugger changes (although 1.4.0-insiders did).
Same issue here. Reverting to an older version of the extension (1.3.1 or 1.3.0) does not fix the problem. The issue appears to be with VS Code Insiders itself, so I suspect the issue should be migrated in the vscode repo.
Nonetheless, a temporary fix around this is to set "externalConsole": true in your launch.json
Issue Type: Bug
I got the following error too.
The terminal process "bash ''" failed to launch (exit code: 127).
Extension version: 1.4.0-insiders2
VS Code version: Code — Insiders 1.57.0-insider (4fd4e10e99eff9eb77408b71c7f58b7ed7458ee5, 2021-05-21T05:13:19.775Z)
OS version: Linux x64 5.11.0-17-generic
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2600) |
| GPU Status | 2d_canvas: enabled gpu_compositing: enabled multiple_raster_threads: enabled_on oop_rasterization: disabled_off opengl: enabled_on rasterization: disabled_software skia_renderer: enabled_on video_decode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 15.41GB (8.51GB free) |
| Process Argv | —unity-launch —crash-reporter-id 23cadddf-5002-4f61-9b06-032b924ce5a5 |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | ubuntu |
| XDG_CURRENT_DESKTOP | Unity |
| XDG_SESSION_DESKTOP | ubuntu |
| XDG_SESSION_TYPE | x11 |
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
pythonvspyt602:30291494
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30291487
pythontb:30258533
vspre833cf:30267465
pythonptprofiler:30281269
vsdfh931cf:30280410
vshan820:30294714
vscorecescf:30290706
pythondataviewer:30285072
vscus158cf:30286554
pythonvsuse255:30303025
vscgsv2:30305091
vscorehov:30301224
vscod805:30301674
This issue is causing me to revert to non-insiders builds. I cannot properly debug my programs.
- with msft cpptools the internal shell cannot open (as stated)
- with external=true, I cannot change the cwd, this setting seems to be ignored
- with webfreak.debug i cannot print ‘*’ and flush stdout (not your problem, sure) but i’m out of options
I do hope this is fixed before this merges to mainline
@WardenGnaw Any ideas about this? Looks like java debugging hit this too.
Oh, it sounds like it’s an issue with VS Code Insiders and not our Insiders.
This issue has been closed automatically because it’s labeled as ‘external’.

