Escaping the \

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Escaping the \
# 1  
Old 12-24-2013
Escaping the \

So I understand that I should be able to ouput a literal \ by escaping it with a preceding \. My problem is that I am trying to ouput a script that will subsequently be run on a different system with UNC pathing, so I want to ouput two \\ in a row, but escaping them both in sequential order is not working. Example:

[server:/informix]# echo "spool \\\\\\data\\out.txt" > test.sql
[server:/informix]# cat test.sql                                         
spool \\data\out.txt

My goal is for the ouput to be:
spool \\\data\out.txt

Last edited by bartus11; 12-24-2013 at 05:34 PM.. Reason: cleared formatting
# 2  
Old 12-24-2013
This is weird as it works for me in BASH on Linux... Try this though:
echo 'spool \\\data\out.txt' > test.sql

# 3  
Old 12-24-2013
Hi bartus11...

Works for me too in OSX 10.7.5, default bash terminal.
Last login: Tue Dec 24 20:53:46 on ttys000
AMIGA:barrywalker~> echo 'spool \\\data\out.txt' > /tmp/test.sql
AMIGA:barrywalker~> hexdump -C /tmp/test.sql
00000000  73 70 6f 6f 6c 20 5c 5c  73 65 72 76 65 72 2e 6e  |spool \\server.n|
00000010  65 74 5c 64 61 74 61 5c  6f 75 74 2e 74 78 74 0a  |et\data\out.txt.|
AMIGA:barrywalker~> _

EDIT: Correct my last...

Last edited by wisecracker; 12-24-2013 at 06:06 PM.. Reason: Does work in shell as well as bash.
# 4  
Old 12-24-2013
You can also use octal code
$ echo -e "spool \0134\\0134data\0134out.txt"
spool \\\data\out.txt

$ echo -e "spool \0134\\0134data\0134out.txt" >test.sql

This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 12-24-2013
I am in KSH on AIX.

echo 'spool \\\data\out.txt' > test.sql

didn't work
$ cat test.sql
spool \\data\out.txt

But octal code did the trick! Thank you Akshay!
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

escaping path

Hi I use : path=/var/www/admin echo "$path" | sed -e 's/\//\\\//g' this return \/var\/www\/admin and is ok. but path2=`echo "$path" | sed -e 's/\//\\\//g'` echo $path2 return an error: sed: -e expression #1, char 9: unknown option to `s' Can anyone help me? Thanks (3 Replies)
Discussion started by: georgian
3 Replies

3. Shell Programming and Scripting

escaping '

I'm cleaning this from some html files style='' but when I try 's/style=\'\''//' I get an unmatched ' error (4 Replies)
Discussion started by: dba_frog
4 Replies

4. Shell Programming and Scripting

Escaping ** correctly

Hello This should be easy, but bash is giving me headaches. At the command line the following command works: duplicity --include /home --exclude '**' / file:///foo Doing that from a script is not straightforward. Note that it is basically a requirement that I place the... (3 Replies)
Discussion started by: brsett
3 Replies

5. UNIX for Dummies Questions & Answers

Escaping comma with \ in file

Hi, I have pipe delimited file in which some of the description fields can have commas. e.g. 1|123|abc,def 2|456|qwert 3|345|aty,try,rty I need to convert this to a 'csv' file BUT i need to add \ before every comma present in the description values (so that my next program can read it as... (3 Replies)
Discussion started by: dsrookie
3 Replies

6. Shell Programming and Scripting

Escaping Special characters

I want to append the following line to /var/spool/cron/root: */7 * * * * /root/'Linux CPU (EDF).sh' > /dev/null 2>&1 How to accomplish this using echo? ---------- Post updated at 04:09 PM ---------- Previous update was at 04:07 PM ---------- "Linux CPU (EDF)" is actually stored in a... (11 Replies)
Discussion started by: proactiveaditya
11 Replies

7. Shell Programming and Scripting

Escaping Special Characters-Help

Hi All, I am having a trouble in passing special characters to a script. As I am new to bash script I dont know how to go and solve this. mypwd=(a+sdfg!h# if i pass $mypwd to a bash script, it is not accepting "(,!,+ etc". It would be a great help if some one can help to escape these... (3 Replies)
Discussion started by: Tuxidow
3 Replies

8. Shell Programming and Scripting

Escaping embedded variables

I'm running into a problem with a differential backup script written in GNU Bash 3.0 - the following stripped down code demonstrates the problem quite nicely. $ DATE="last tuesday" $ date --date="$DATE" Tue Jan 6 00:00:00 PST 2009 So far so good. $ CMD="date --date=\"$DATE\"" $... (6 Replies)
Discussion started by: vertigo23
6 Replies

9. UNIX for Dummies Questions & Answers

Escaping backslash

I have a variable containt something like this, c:\mask\mask. How can I escape "\" in the values? I want the value as it it. (9 Replies)
Discussion started by: swmk
9 Replies

10. Shell Programming and Scripting

Escaping '*' in Bash

I have the following situation ============ export DirectoryName=/tmp/xyz if ; then some_new_env=$DirectoryName"/*" ======================= I tried all the ways of escaping the '*', but still the shell seems to expand the '*' character. I want some_new_env to contain "/tmp/xyz/*" ... (7 Replies)
Discussion started by: rkshukla14
7 Replies
Login or Register to Ask a Question