If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Escaping a \

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-04, 09:33
rkrishnan73 rkrishnan73 is offline
Registered User
 
Join Date: Mar 2004
Posts: 10
Escaping a \

I want to include an argument that contains a \ in one of the commands. These arguments are in a file (one in a line). Ex:

C:\
D:\

If I perform a while loop to read these lines,

while read varName
do
echo $varName
done < $argFile

the loop exits without executing even once. How do I read these variables by escaping the \ ?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-01-04, 09:49
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
If the last char of the line is \, 'read' assume that there is a continuation line.
A solution is to escape the \ :
'C:\' must be converted to 'C:\\' before 'read'
Code:
sed 's/\\$/\\\\/' $argFile | \
while read varName
do
   echo $varName
done
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-01-04, 10:46
rkrishnan73 rkrishnan73 is offline
Registered User
 
Join Date: Mar 2004
Posts: 10
That seems to work!! Thanks buddy.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On