Escaping the * character in ksh.

Hi All,

In ksh script i'm trying to assign "sqlstmt1" varaible value,

update VAREntryTb set VAR10num = VAR1num * Mltplr where BusD = '$val1' and RunI = 1"`

Hence i wrote below statement, the issue with this is shell is expanding "*" character adn thus subistuting it with the content of my present directory,

sqlstmt1=`echo "update VAREntryTb set VAR10num = VAR1num * Mltplr where BusD = '$val1' and RunI = 1"`

when i escape it with "\" like,
sqlstmt1=`echo "update VAREntryTb set VAR10num = VAR1num \* Mltplr where BusD = '$val1' and RunI = 1"`

then everything is fine except backward slash is also coming as part of whole string, something like,

update VAREntryTb set VAR10num = VAR1num \* Mltplr where BusD = '$val1' and RunI = 1

Can someone help me in getting the things right here ?

You don't need to backslash the asterisk inside double quotes; it will not be used for globbing when it's quoted.

But if i don't backslash it, then "*" is getting replaced with all the file name in present directory. Hope i'm clear with my question.

Try:

> val1=test
> set -f                                                                                         
> sqlstmt1="update VAREntryTb set VAR10num = VAR1num *  Mltplr where BusD = '$val1' and RunI = 1"
> echo $sqlstmt1                                                                                 
update VAREntryTb set VAR10num = VAR1num * Mltplr where BusD = 'test' and RunI = 1
> set +f

sqlstmt1="update VAREntryTb set VAR10num = VAR1num * Mltplr where BusD = '$val1' and RunI = 1"

Then put the variable sqlstmt1 in double quote

echo "$sqlstmt1"

the value of the variable varl1 will also get replaced.

If it's inside double quotes, it does not get replaced with all the file names in the present directory. Hope I'm clear with my answer.

Thanks all for the your help, both the above solution worked fine.

Even i was wondering why "*" is getting expanded even if put it in double quotes. The problem was with my coding only, as after setting the sqlstmt variable, i was writing it's content to file, like
echo $sqlstmt >> sqlfile.txt, so here lies the problem, as i changed it to echo "$sqlstmt" >> sqlfile.txt. And since i didn't turn off the "-x" flag i didn't got it noticed.

Also can you kindly give me brief discription, as what "set -f /+f " does ?

Thanks all for your help again.