detecting command not found in bash script

前端 未结 3 564
余生分开走
余生分开走 2020-12-18 09:11

I have a series of command to execute. However I need to exit whenever \'command is not found\' error occurs. So post execution check of output is not an option

The

3条回答
  •  没有蜡笔的小新
    2020-12-18 09:53

    If the command is not found, the exit status should be 127. However, you may be using bash 4 or later and have a function called command_not_found_handle defined. This function is called if a command cannot be found, and it may exit 0, masking the 127 code.

    Running type command_not_found_handle will show the definition of the function if it is defined. You can disable it by running unset command_not_found_handle.

提交回复
热议问题