Error: if condition

please follow below code

if [ eval echo '$lck_'$TABLE != "" ]; then

its giving me an error as "test1.sh: line 3: [: too many arguments"

if i store eval echo '$lck_'$TABLE != "" result into sme variable n then use in if cond its working fine...say

r=$(eval echo '$lck_'$TABLE != "")
if [ r != "" ]

can anyone tell me how to do inside if condition...with out use any variable..

TIA

Try this

# lck is empty nothing to print
$ echo $lck  

# table is empty nothing to print
$ echo $table

# lck is as not NULL print Yes
$ lck=as
$ if [ $lck'_'$table != "_" ]; then echo "Yes";else echo "No";fi
Yes

# Make lck empty print No
$ unset lck
$ if [ $lck'_'$table != "_" ]; then echo "Yes";else echo "No";fi
No

You can put the $(...) construct directly in the test, although i'm not sure what you're trying to achieve.

Replace the if statement with

if [ "$(echo eval '$lck_'$TABLE)" != "" ]; then

Your solution fails

$ lck_=as
$ if [ "$(echo eval '$lck_'$TABLE)" != "" ]; then echo "Yes";else echo "No";fi
Yes
$ unset lck_
$ echo $lck_

$ echo $TABLE

$ if [ "$(echo eval '$lck_'$TABLE)" != "" ]; then echo "Yes";else echo "No";fi
Yes

@ Akshay, you are right. Good catch. But I'm not sure if it is a valid scenario to have a variable like lck_

I presume the variable TABLE would vary and will be attached to lck_ as in

lck_T1 
lck_T2
lck_T3 and so on

variable lck_ is valid, But I am suspecting user might have variable lck and TABLE

if not he can use this

$ unset lck_
$ unset TABLE
$ if [ -z $lck_$TABLE ];then echo "Empty";else echo "Something is there";fi
Empty
$ lck_=test
$ if [ -z $lck_$TABLE ];then echo "Empty";else echo "Something is there";fi
Something is there

In #4
if [ "$(echo eval '$lck_'$TABLE)" != "" ]; then

Resulting

$ TABLE=test2
$ echo $(echo eval '$lck_'$TABLE)
eval $lck_test2

eval '$lck_' is treated as string