-
Book Overview & Buying
-
Table Of Contents
Linux Command Line and Shell Scripting Bible - Third Edition
By :
In the if-then statement, you have only one option for whether a command is successful. If the command returns a non-zero exit status code, the bash shell just moves on to the next command in the script. In this situation, it would be nice to be able to execute an alternate set of commands. That's exactly what the if-then-else statement is for.
The if-then-else statement provides another group of commands in the statement:
if command
then
commands
else
commands
fi
When the command in the if statement line returns with a zero exit status code, the commands listed in the then section are executed, just as in a normal if-then statement. When the command in the if statement line returns a non-zero exit status code, the bash shell executes the commands in the else section.
Now you can copy and modify the test script to include an else section:
$ cp test3.sh test4.sh
$
$ nano test4.sh
$
$ cat test4.sh
#!/bin/bash
# testing the else section
#
testuser...
Change the font size
Change margin width
Change background colour