The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Escaping specific character in awk brainyoung Shell Programming and Scripting 8 12-16-2008 11:14 PM
problem escaping newline in ksh JamesByars Shell Programming and Scripting 7 01-05-2008 05:51 PM
Escaping '*' in Bash rkshukla14 Shell Programming and Scripting 7 04-04-2007 11:45 PM
bash script help: escaping the '*' mark_nsx Shell Programming and Scripting 18 10-07-2005 08:20 AM
escaping * in korn shell prekida Shell Programming and Scripting 3 07-13-2005 05:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2008
arvindcgi arvindcgi is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
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 (permalink)  
Old 05-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You don't need to backslash the asterisk inside double quotes; it will not be used for globbing when it's quoted.
  #3 (permalink)  
Old 05-19-2008
arvindcgi arvindcgi is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
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 (permalink)  
Old 05-19-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
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 (permalink)  
Old 05-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #6 (permalink)  
Old 05-19-2008
arvindcgi arvindcgi is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
Smile

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.
  #7 (permalink)  
Old 05-19-2008
sanjaypraj sanjaypraj is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 7
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0