Skip to content

Instantly share code, notes, and snippets.

@quickgrid
Created April 1, 2016 05:34
Show Gist options
  • Save quickgrid/ef2f7a8c27cd20fd178e6d652a4bf482 to your computer and use it in GitHub Desktop.
Save quickgrid/ef2f7a8c27cd20fd178e6d652a4bf482 to your computer and use it in GitHub Desktop.
This just an example of expression evaluation different way. Also equality and even odd checking in a different way.
#!/bin/bash
# Do not use space before and after equal sign.
a=1
b=3
sum=`expr $a + $b`
sum=$(( $sum + 5 ))
echo $sum
# If condition, must be closed with fi
a=2
b=2
if [ $a -eq $b ];then
echo "match"
else
echo "not match"
fi
# Check if even
read input
two=2
val=$(( $input / $two ))
val=$(( $val * $two ))
#echo $val
if [ $val -eq $input ];then
echo "Even"
else
echo "Odd"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment