Bulletproofing

The ultimate bulletproofing of a script comes by combining many of the thoughts presented in this chapter. The goal is to make the script impervious to any kind of input the user might throw at it (or that it might read from a file). This special-case “what-if” code can be so detailed and cumbersome to write that it takes up more lines in your script than the main production logic flow. Therefore, I suggest that you implement these ideas in your nonpersonal scripts.

The following example shows an example of bulletproofing.

 $ cat gcdksh #! /bin/ksh function gcd { # Function to generate gcd between two numbers integer u v r u=$1 v=$2 while ((v)) # Key gcd loop do r=u%v u=v v=r done print $u # Returns value to caller of function ...

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.