Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test condition

Status
Not open for further replies.

mangok

Technical User
Oct 24, 2001
7
IN
hi all,
I want to run the following script :

dt=`date +%d/%m/%y`
echo $dt
mm="04/10/03"
echo $mm
if [ "04/010/03"=="15/10/03" ]
then
echo "hi "
else
echo "no"
fi

but i get the result as "hi" but expected is "no"
what is the prob with current script
I have used different Operator as "-eq" and "==" but still result remains same
pls help
TIA
Mangesh
 
Hi,
make sure you have spaces between your operands and the operator.

if [ "04/010/03"=="15/10/03" ]

should be

if [ "04/010/03" -eq "15/10/03" ]

You use -eq for strings.

Without spaces it thinks

"04/010/03"=="15/10/03"

is one big variable and it always evaluates to TRUE.




 
hi,
I have tried that also but still i get "hi"
i.e. after trying :

dt=`date +%d/%m/%y`
echo $dt
mm="04/10/03"
echo $mm
if ["04/010/03" -eq "$dt"]
then
echo "hi "
else
echo "no"
fi


i get " hi"
 
you lost the brackets !
if [ "04/010/03" -eq "15/10/03" ]



Dickie Bird (:)-)))
 
Try this:

#!/bin/ksh
dt=`date +%d/%m/%y`
echo $dt
mm="04/10/03"
echo $mm
if [ "04/10/03" = "$dt" ]
then
echo "hi"
else
echo "no"
fi

Not sure why single = seems to work, when == ought to be the logical solution
Any ideas?

 
I was asleep - the -ne, -eq -gt are used for integers !
=, != , etc are used for strings.

Dickie Bird (:)-)))
 
Try this:
Code:
if test $mm = $dt; then
  echo "Hi"
else
  echo "No"
fi

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top