June 2017
Beginner
502 pages
11h 26m
English
So far, we have seen how a script terminated with the exit status of the last command issued, and how a $? allows us to read the exit value. This is possible because every command returns an exit code, whether issued on the command line or from inside a script, and even functions that we can think of as a compound of commands return a value. Now we are going to see how a script can return an exit code on its own, despite of the result of the last command issued:
#!/bin/bash counter=10 while [ $counter -gt 0 ]; doecho "Loop number: $((counter--))"doneexit 20
We took one of our previous scripts and added this:
exit 20
As you can see, we used the command exit followed by a positive number to give an exit code. Remember that ...
Read now
Unlock full access