Exit Codes of shell commands
Whenever a command ends and returns the control to the parent process, it returns exit codes between 0 and 255. Exit code 0 means the command was successful, and any other exit code means, the command was unsuccessful. You can view the exit code after running any command by accessing the $? variable. See the example below.
You can manually set an exit code for your shell script. This can be used with conditional statements to convey if the script’s purpose was achieved or not.
Example
#!/bin/sh read x if [ $x -ne 10 ] then echo failed exit 1 else echo passed exit 0 fi
How to Create a Shell Script in linux
Shell is an interface of the operating system. It accepts commands from users and interprets them to the operating system. If you want to run a bunch of commands together, you can do so by creating a shell script. Shell scripts are very useful if you need to do a task routinely, like taking a backup. You can list those commands and execute them all with just a single script. Let’s see how you can create a shell script and run it on Linux.