PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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 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 : 2943
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

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 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 : 2943
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

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