February 2020
Intermediate to advanced
292 pages
8h 54m
English
In step 1, the cp command failed, as file and file2 don't exist. By querying echo $?, we get the error code; in this case, it is 1. This is particularly useful when writing bash scripts where we might need to check for a particular condition.
In step 2, the script just lists the does_not_exist.txt file and reads the error code returned. If all goes fine, it prints an acknowledgment message and returns 0. Otherwise, it returns the error code 11.
By running the script, we get the output as follows:

Here, we notice a couple of things:
Under the hood, ...
Read now
Unlock full access