how to terminate script


The command exit terminates script. The syntax of exit:

exit N

You can specify N value from 0-255. This value interpret error code. The value 0 means script was executed successful. Values grater than 0 mean script was executed with error.

If you want to terminate script on specific line enter:

exit 1

If your script is running and you need to terminate it use command ps to get PID (process ID) and command kill to kill the process.

ps aux
kill -KILL -PID

If you want to terminate script when any command fails enter at the top of script:

set -e

When error occurs you can get error code with $?.

Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.