We've seen that one way to interact with the Linux kernel is through the shell, by invoking commands. A command can fail, as we can imagine, and a way to communicate a failure is to return a non-negative integer value. 0, in most cases, means success. This recipe will show you how to deal with error handling on the shell.
Handling a Linux bash error
How to do it...
This section will show you how to get errors directly from the shell and via a script, which is a fundamental aspect of script development:
- First, run the following command:
root@e9ebbdbe3899:/# cp file file2
cp: cannot stat 'file': No such file or directory
root@e9ebbdbe3899:/# echo $?
1
- Create a new file called first_script.sh and type in the...