IF stategreat than 1 and less than 20


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers IF stategreat than 1 and less than 20
# 1  
Old 01-31-2006
Data IF stategreat than 1 and less than 20

I have this short statement:


size=1
VAR=` wc -c datafile | awk -F" " '{print $1}' `
if [ $VAR -gt size ]
then
dowhatIeed

Question:

How can I make my if statement greater than 1 and less than 20?

How can I make my if statement greater than 1 and equal to 20?

Please advise!
# 2  
Old 01-31-2006
Quote:
Originally Posted by bobo
I have this short statement:


size=1
VAR=` wc -c datafile | awk -F" " '{print $1}' `
if [ $VAR -gt size ]
then
dowhatIeed

Question:

How can I make my if statement greater than 1 and less than 20?

How can I make my if statement greater than 1 and equal to 20?

Please advise!
Code:
How can I make my if statement greater than 1 and less than 20? 
size=1
VAR=` wc -c datafile | awk -F" " '{print $1}' ` 
if [[ $VAR -gt $size && $VAR -lt 20 ]] ; then
dowhatIeed
fi ;

Code:
How can I make my if statement greater than 1 and equal to 20?
size=1
VAR=` wc -c datafile | awk -F" " '{print $1}' ` 
if [[ $VAR == 20 ]] ; then
dowhatIeed
fi ;

# 3  
Old 02-01-2006
My data file has 15 characters:


VAR=` wc -c datafile | awk -F" " '{print $1}' `
if [[ $VAR -gt 1 && $VAR -lt 20 ]]
then
echo "great than 1 "
else
echo "less than 1"
fi

When I run this program, I got this message:

> ./if
./if: [[: not found
less than 1

Please tell me what do I do wrong here!
# 4  
Old 02-02-2006
What shell are you using? Vino's syntax (the [[..]]) will work only with ksh or bash. From the error message it looks like you are using sh. Try using ksh/bash.
# 5  
Old 02-02-2006
thanks! I will try
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question