Linux Bash If Greater Than Or Less Then Conditions

Go down

Linux Bash If Greater Than Or Less Then Conditions Empty Linux Bash If Greater Than Or Less Then Conditions

Post by jamied_uk on 20th July 2016, 10:28





Code:
#!/bin/bash
# Usage: ./if.sh
#
var=20

if [ "$var" -gt 15 ] # Need spaces between brackets!
then : # do nothing
else
    echo "$var" # echo the var if less than true!
fi
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Linux Bash If Greater Than Or Less Then Conditions Empty Re: Linux Bash If Greater Than Or Less Then Conditions

Post by jamied_uk on 20th July 2016, 10:45

If = to or not = to that is the question!




Code:
#!/bin/bash
# Usage: ./if_not.sh 10
#
var=("$@") # User Input

if [ "$var" != 15 ] # Need spaces between brackets!
then : # do something
echo "$var Is NOT Equal To 15"
else
    echo "$var Is Equal To 15"
fi
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum