I have a shell script file, I check the $? is 0 to judge the script run successfully.
When the script has a error command, it will run failed, I think it will exit by 127, but if I use bash -l
it still return 0, this make me dont know there is running successfully or command not found. BUt if no -l
it return 127
there is my demo:
[root@T /tmp]# cat _script.sh
no_such_cmd
[root@T /tmp]# bash _script.sh
_script.sh: line 1: no_such_cmd: command not found
[root@T /tmp]# echo $?
127
[root@T /tmp]# bash -l _script.sh
no_such_cmd : command not found
[root@T /tmp]# echo $?
0
[root@T /tmp]# no_such_cmd
no_such_cmd : command not found
[root@T /tmp]# echo $?
0
[root@T /tmp]# zsh
[root@T]/tmp# no_such_cmd
zsh: command not found: no_such_cmd
[root@T]/tmp# echo $?
127