1754298 Members
2434 Online
108813 Solutions
New Discussion юеВ

if statment

 
kamal_15
Regular Advisor

if statment

please help

this line return error. idon't know how to write it

------------------------------------
if [ $var1 | awk ' {print $2} ' = " " ]
then
echo "anything"
fi
-------------------------------------

i want to check if second part of variable is empty?

thanks
11 REPLIES 11
RAC_1
Honored Contributor

Re: if statment

what does variable look like??
There is no substitute to HARDWORK
Tony Scully_2
Valued Contributor

Re: if statment

From what you say there are two parts to the variable? Is it not possible to have 2 variables and just test the seconf one?
You CAN do that on HP
kamal_15
Regular Advisor

Re: if statment

var1 contain this tring
---------------------
tabname anyname
---------------------

Tony Scully_2
Valued Contributor

Re: if statment

try

echo "$var1" before the pipe?
You CAN do that on HP
Tony Scully_2
Valued Contributor

Re: if statment

Actually, don't htink that helps because if the seond part is blank then no $2 will get set.

Sorry
You CAN do that on HP
RAC_1
Honored Contributor

Re: if statment

seond_var=$(awk -F " " '{print $2}' ${var})

[[ ${second_var} = "" ]]
then
echo "no second_var"
fi
There is no substitute to HARDWORK
kamal_15
Regular Advisor

Re: if statment

many thankx
but i tryed to execute it in one statment

if i find solution i will tell u

thankx again
Tony Contratto
Respected Contributor

Re: if statment

This should do it:

if [ "$(echo ${var1} | awk '{print $2}')" = "" ]
then
echo "anything"
fi


--
Tony
got root?
Taulant Shamo
Frequent Advisor

Re: if statment

Hi Kamal,

Try this I could work.


if (test $var1 = `awk '{print $2}'`=" ")
than echo "anything"
exit
fi

Taulant