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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bourne Shell: Special characters Input Prevention totziens Shell Programming and Scripting 37 04-23-2008 04:05 AM
Searching for escape characters timcs Shell Programming and Scripting 8 05-25-2007 06:29 AM
Check for special characters in a script sumesh.abraham Shell Programming and Scripting 7 12-18-2006 09:15 AM
escape characters.. sharsin2001 Shell Programming and Scripting 9 11-06-2006 10:52 AM
Can't stop shell interpreting special characters Doug97 Shell Programming and Scripting 2 11-23-2005 09:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-28-2007
rogers42 rogers42 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Need help to escape special characters in Korn shell script

Hi,

I would like to display the following message from my shell (Korn) script

Copy "old_file.txt" to "new_file.txt"

My code looks as follows

print "Copy "old_file.txt" to "new_file.txt""

However, when I execute the script, I get the following output

Copy old_file.txt to new_file.txt

Can somebody please help me with the syntax to escape the double quotes (") ?

Thanks in advance.

rogers42
  #2 (permalink)  
Old 12-28-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Code:
$ print "Copy \"old_file.txt\" to \"new_file.txt\""
Copy "old_file.txt" to "new_file.txt"
$
  #3 (permalink)  
Old 12-29-2007
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 499
You could have also gone with ...
Code:
[mddev:/home/cameron]
$ print 'Copy "old_file.txt" to "new_file.txt"'
Copy "old_file.txt" to "new_file.txt"
  #4 (permalink)  
Old 12-29-2007
rogers42 rogers42 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Thanks for the tips folks. Much appreciated.

rogers42
  #5 (permalink)  
Old 04-29-2008
Thinkpositiv Thinkpositiv is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
Hi,

I also need some quoting help. I tracked my problem down in a simple example.
I have a grep that is working if typed at the shell prompt (it is important for me to have a space in the character class):
Code:
grep -E '[a-zA-Z ]{30}:' myFile
But included in a script file (lets say file 'runMe') like the following:
Code:
#!/bin/ksh
typeset pattern='[a-zA-Z ]{30}:'
echo "Command to be executed: grep -E $pattern myFile"
grep -E $pattern myFile
Executing the file 'runMe', I get the following error:
grep: RE error in '[a-zA-Z [ ] imbalance or syntax error

I googled/searched here for the error and for quoting or inserting something else which recognizes a space character, but with no success yet.
Also I tried various quotings in runMe, like "'[a-zA-Z ]{30}:'" or "\"[a-zA-Z ]{30}:\"" or quoting the space character like "[a-zA-Z ]{30}:" but all lead to the same error message. Seems like it is breaking at the space?

Curious for me:
If I execute the script and copy the line which is printed by the 'echo' statement and paste this line at the command prompt, that works! It just doesn't work within the script...

Maybe this not the adequate topic, because its more a grep issue than a quoting issue. If so, please be patient with me

FYI:
I'm relatively new to unix.
In 'myFile', I want to (simplified for this issue) match lines, that have the first 30 characters being (a letter or a space), followed by a colon.
I've aliased grep to /usr/xpg4/bin/grep (and also tried /usr/xpg4/bin/grep manually without alias).

thanks in advance for any hints, Thinkpositiv

Last edited by Thinkpositiv; 04-29-2008 at 10:32 AM..
  #6 (permalink)  
Old 05-02-2008
Thinkpositiv Thinkpositiv is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
Well, I got it myself. I missed the double quotes when using the variable (not a declaration time of the variable)!

Code:
#!/bin/ksh
typeset pattern="[a-zA-Z ]{30}:"
echo "Command to be executed: grep -E $pattern myFile"
grep -E "$pattern" myFile
Hope this helps someone
  #7 (permalink)  
Old 05-14-2009
Thinkpositiv Thinkpositiv is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
Hi,

I'm back with a similar issue
Basically I'm grep'ing a file for a pattern. The pattern contains " (double quotes) and a space. So I escaped the quotes. But how do I use this variable in the grep call?
Code:
typeset searchString="path=\"asdf\" mode=\"jkl\""
typeset found=`grep "$searchString" $cs_rte_configtransform` #(a)
typeset found=`grep '$searchString' $cs_rte_configtransform` #(b)
Neither (a) nor (b) works. From my understanding I'd have to use (a), but searchString should contain path=\"asdf\", so I need to declare it like this?
Code:
typeset searchString="path=\\\"asdf\\\" mode=\\\"jkl\\\""
Still no results, the variable found is always empty, although the searchString manually pasted into the grep call works.

Has anyone an idea/hint for me?
Thanks, regards, Thinkpositiv
Sponsored Links
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 06:51 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