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.


23 visits (1 today, 5 this week, 16 this month, 23 this year)
Uptime: 10:34:41 up 1 day, 17:00, 0 users, load average: 0.00, 0.00, 0.00
44.201.131.213 GET from server z.lam1.us

Thursday, March 28, 2024 @ 10:34:41 AM
z.ServerAdmin@lam1.us