Example 2

Concepts:
Statements while and if, mathematical operations and continue command.

Text:
Implement a bash script that prints the number between 1 and 20, with the exception of the numbers 4 and 13.

An example of the output of the script is:

Print the numbers between 1 and 20 (with the exclusion of the numbers 4 and 13).
1 2 3 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20

Solution:

bash_ex2.sh
#!/bin/bash
 
LIMIT=20  # Superior limit
 
echo "Print the numbers between 1 and 20 (with the exclusion of the numbers 4 and 13)."
 
a=0
 
while [ $a -lt "$LIMIT" ]
do
    a=$(($a+1))
    # a=$[$a+1] # Another possible way to compute mathematical operations
 
    if [ "$a" -eq 4 ] || [ "$a" -eq 13 ]  # Exclusion of 4 and 13 numbers
    then
        continue  # Skip the rest of this cycle
    fi
 
    echo -n "$a "
done 
echo # Print new line
 
exit 0