Escaping the * character in ksh.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Escaping the * character in ksh.
# 1  
Old 05-19-2008
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 ?
# 2  
Old 05-19-2008
You don't need to backslash the asterisk inside double quotes; it will not be used for globbing when it's quoted.
# 3  
Old 05-19-2008
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.
# 4  
Old 05-19-2008
Try:

Code:
> 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

# 5  
Old 05-19-2008
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.
# 6  
Old 05-19-2008
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.
# 7  
Old 05-19-2008
Bug

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Escaping a variable in ksh

I am trying to echo a variable exactly to a script- echo "${var1} ${var2} >> output.output Gives me a blank file. I would like output.output to basically say: ${var1} ${var2} I think I need to use a special escape character for variables. Am I right in assuming that, and is it the... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. Shell Programming and Scripting

sed - replacement file path with variable - Escaping / character

Hi,, I have the line below in a file: $!VarSet |LFDSFN1| = '"E:\APC\Trials\20140705_427_Prototype Trial\Data\T4_20140705_Trial_Cycle_Data_13_T_Norm.txt" "VERSION=100 FILEEXT=\"*.txt\" FILEDESC=\"General Text\" "+""+"TITLE{SEARCH=NONE NAME=\"New Dataset\" LINE=1I want to write a script to change... (2 Replies)
Discussion started by: carlr
2 Replies

3. Shell Programming and Scripting

ksh escape a character

friends, I have a situation where i am using a $RANDOM function along with the filename, I want this to be escaped by the OS in the first assignment (works as expected) and executed in the second assignment (does not execute $RANDOM) filename1=filename1_\$RANDOM echo $filename1... (3 Replies)
Discussion started by: Balaji M
3 Replies

4. Shell Programming and Scripting

please explain why this ksh echo deletes character

Please explain why this works. Am unable to find another definition for the '%', which would explain this behaviour: spaceLeft=`df -h /myPartition | tail -1` # output looks like: /dev/sda5 10G 1.2G 12G 29% / set -- $space #this deletes the trailing '%' sign, which is... (6 Replies)
Discussion started by: frododot
6 Replies

5. UNIX for Advanced & Expert Users

Escaping special character stored in variables : perl

Hi just for regular use i m working on small module written in perl for getting date in specified format like i have to specify date format and then seperator to seperate date i am 95% done. now i m sure explanation i gave is not good enough so i am putting output here : C:\Documents and... (2 Replies)
Discussion started by: zedex
2 Replies

6. Shell Programming and Scripting

Escaping specific character in awk

Hello there, I have a bit of dirty delimited file, I mentioned dirty because, the delimiter can also appear in wrong positions. However, one uniqueness of this file is whenever the delimiter appear inside the double quote, then do not consider as delimiter, if it appear outside double then... (8 Replies)
Discussion started by: brainyoung
8 Replies

7. UNIX for Dummies Questions & Answers

odd character (^M) from .sh when chagining to .ksh

// AIX 5.3 I am trying to use .sh after changing it to .ksh Obviously, it doesn't like the file extension change. I am seeing a lot of odd characters (^M) like below: Init_Part2 ()^M^M {^M^M AWTRACE "AW SET"^M^M set | grep -e CFG_ -e OUTDIR_ENV^M^M AWTRACE "AW SET"^M^M ^M^M if ;... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

8. Shell Programming and Scripting

problem escaping newline in ksh

Hi, I did the below. $ print "\\n" $ I am curious, why does \\n give two new lines? I would have thought that the first \ would escape the second \, and so we'd get \n printed. But we didn't. Any ideas? Thanks. (7 Replies)
Discussion started by: JamesByars
7 Replies

9. Shell Programming and Scripting

KSH - Character Replacement

Hey all. Easy question. I have a (ksh) varaible x. It contains the following (for example): N557788 I want to replace the "N" with a "-". I've done this before but for the life of me I cannot remember how I did it. Thanks. mtw (2 Replies)
Discussion started by: mixxamike
2 Replies

10. Shell Programming and Scripting

Newline character not working for ksh

Newline character "\n" not working for ksh in linux AS 3.0 Command : $echo "Hi\nHi" $Hi\nHi $ Expected output : $echo "Hi\nHi" Hi Hi $ Can some help me on this Thanks in advance Sanish. (11 Replies)
Discussion started by: sanikv
11 Replies
Login or Register to Ask a Question