using && in if statement ..

Hi All,

Can some one tell me how to get run the following:

data1="hello"
data2="world"
if [ "$data2" != "world" && "$data1" != "hello"]
then
{
echo "good afternnon"
}
else
{
echo " good morning"
}
fi

The above code gives me an error ad below :
./if.h: line 3: [: missing `]'

Thanks in advance
Js

Dear jisha,

try this

data1="hello"
data2="world"
if [ "$data2" != "world" ]
then
if [ "$data1" != "hello" ]
then
echo "good afternnon"
fi
else

echo " good morning"

fi

Regards,
Pankaj

try:

if [ "$data2" != "world" ] && [ "$data1" != "hello" ]

Don't forget to let a space before ] and after [ !
Here is the code :

data1="hello"
data2="world"
if [ "$data2" != "world" ] && [ "$data1" != "hello" ]
then
{
        echo "good afternnon"
}
else
{
        echo " good morning"
}
fi

which code is this ???? shell script ?????

Thanks to all !!

Its working now.. I did a lot of debugging still i didnot get ...I think the problem was with the spacing

Thank you so much

Js

If you want to make your schell script more efficient you should use the shell builtins

#!/usr/bin/ksh

data1="hello"
data2="world"

if [[ "$data2" != "world" && "$data1" != "hello" ]]
then
    print "good afternnon"
else
    print "good morning"
fi

u can also use this one:)

if [ "$data2" != "world" ] -a [ "$data1" != "hello" ]