![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Sed and awk backslash characters | potro | Shell Programming and Scripting | 7 | 05-19-2008 09:34 AM |
| How to handle backslash in grep string | rajbal | UNIX for Advanced & Expert Users | 6 | 06-18-2007 09:22 PM |
| How ro handle backslash character in grep? | rajbal | Shell Programming and Scripting | 1 | 06-18-2007 09:19 PM |
| ignoring backslash while executing command | agalkin | Shell Programming and Scripting | 6 | 11-16-2005 06:04 PM |
| Adding a backslash to users' input | netguy | Shell Programming and Scripting | 13 | 04-30-2004 06:06 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
backslash issues
Hi,
I have a script which looks through an input file and takes data from the file to use within the script. Everything works fine until the script reads the item \windows\directory\structure\ from the input file into a variable. As unix sees the backslash as an escape character, the variable, when echoed shows windowsdirectorystructure when the literal \windows\directory\structure\ is required. I tried excaping the escape characters in the input file so that the variable included them, ie putting \\windows\\directory\\structure\\ into the input file. This came back with the same incorrect result too. I also tried \\\windows\\\directory\\\structure\\\ just in case the shell interpreted the variable another time but this showed the same result too. I also tried using '\windows\directory\structure\' including single quotes in the input file but the variable literally is '\windows\directory\structure\' including single quotes. If I try assigning the variable on the command line rather than from within the script, I get the desired result. ie var='\windows\directory\structure\' echo $var \windows\directory\structure\ Does anyone have any advice on how I can get the variable in the script to equal \windows\directory\structure\ ? Many thanks Helen |
|
||||
|
Hi,
The input file I use is slightly different and similar to the following: field1,field2,field3,C:\\path\\to\\first\\windows\\file,field5 field1,field2,field3,C:\\path\\to\\second\\windows\\file,field5 The script is similar to this: #!/bin/sh while read var do dir=`echo $var | cut -d , -f 4` echo $dir done < files.txt exit 0 When running it i get: $test.sh C:\path o irst\windows ile C:\path o\second\windows ile $ Thanks for your help Helen |
|
|||||
|
Give this a try
Code:
#!/bin/sh
while read var
do
dir=`echo $var | cut -d , -f 4 | sed 's/\\\\/\\\\\\\\/g'`
echo $dir
done < files.txt
exit 0
Code:
field1,field2,field3,C:\\\\path\\\\to\\\\first\\\\windows\\\\file,field5 field1,field2,field3,C:\\\\path\\\\to\\\\second\\\\windows\\\\file,field5 This nightmare only seems to rear it's ugly head under really old original Bourne shells. I've tested my original solution under bash and ksh and it works fine. The original bourne shell on HP-UX (/usr/old/bin/sh) shows this problem, and requires backslash-city as above. Peace ZB |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|