Summary

7.4. Summary

In this chapter we learned how to build conditions into our scripts so that different actions can be undertaken upon success or failure of a command. The actions can be determined using the if statement. This allows you to perform arithmetic and string comparisons, and testing of exit code, input and files needed by the script.

A simple if/then/fi test often preceeds commands in a shell script in order to prevent output generation, so that the script can easily be run in the background or through the cron facility. More complex definitions of conditions are usually put in a case statement.

Upon successful condition testing, the script can explicitly inform the parent using the exit 0 status. Upon failure, any other number may be returned. Based on the return code, the parent program can take appropriate action.


213 visits (2 today, 13 this week, 42 this month, 213 this year)
Uptime: 07:41:07 up 3 days, 13:24, 3 users, load average: 0.00, 0.00, 0.00
3.145.63.15 GET from server z.lamurakami.com

Saturday, December 21, 2024 @ 7:41:07 AM
z.ServerAdmin@lam1.us