More actions
Mediawiki's links are made with square brackets and that messes up the if statements
imported>Sjwhitak (Moved messed up link to real link.) |
imported>Sjwhitak (Mediawiki's links are made with square brackets and that messes up the if statements) |
||
=== If, Elif, Else ===
<pre>
▲ #!/bin/bash
▲ echo "Enter a number:"
▲ read number
▲ # if and elif both have a "then" associated with it
▲ if [ $number -eq 1 ]
▲ then
▲ echo 1
▲ elif [[ $number -eq 2 ]]
▲ then
▲ echo 2
▲ else
</pre>
▲ echo "You can't get anything right you hopeless loser"
▲ fi
This is a simple example that just reads in a number and checks to see if the number is either 1, 2, or, if neither of these are true, will just insult you. The syntax here is pretty simple. You have the if statement which uses square brackets for the conditional and elif statements which use double square brackets. There is also the default else statement and the whole statement is closed off by a fi (if backwards).
|