Download Learning the bash Shell, 3rd Edition By Cameron

Transcript
then
# the startup directory exists so read any initialisation file.
echo "initialising file processing..."
11.1.2. Variables and Constants
Headers and comments are just one way to document your code. Another is by the use of descriptive
variable names. Good variable names should give an indication of what the variable represents. Names
like "x", "resn" or "procd" will only have meaning at the time that you write the script. Six months
down the track and they will be a mystery.
Good names should be short but descriptive. The three examples above might have been more
meaningfully written as "file_limit", "resolution", and "was_processed". Don't make the names too
long; the name "horizontal_resolution_of_the_picture" just clutters a script and takes away any
advantage in making the name so descriptive.
Constants should be in uppercase and should normally be declared as read-only:
declare -r CAPITAL_OF_ENGLAND="London"
You should always avoid "magic numbers" sprinkled throughout the code by using constants. For
example:
if [[ $process_result == 68 ]]
...
should be replaced with:
declare -ir STAGE_3_FAILURE=68
...
if [[ $process_result == $STAGE_3_FAILURE ]]
...
Not only does this make the code more readable but it makes changing the value easier, especially if it
is used numerous times in the script.