Linux Bash If Greater Than Or Less Then Conditions

View previous topic View next topic Go down

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
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

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
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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