Operating System - HP-UX
1834926 Members
2588 Online
110071 Solutions
New Discussion

Re: echo and backslash characters

 
SOLVED
Go to solution
Adrian Brown_1
New Member

echo and backslash characters

Hi,

I'm writing a ksh script with the following line:

echo $ATTLINE >> $TEMPFILENAME

The variable $ATTLINE contains a string of characters which can include consequtive backslash characters i.e. \
The echo command sees the \\ as an escape sequence and I lose one of the backslash characters thus corrupting my file.

Is there a way of stopping echo from doing this ? or are there any other commands I can use to append the variable to the file without losing characters ?

Thanks,

Adrian.
5 REPLIES 5
Rodney Hills
Honored Contributor
Solution

Re: echo and backslash characters

The -r option on the ksh print command will leave backslashes alone.

print -r $ATTLINE >> $TEMPFILENAME

HTH

-- Rod Hills
There be dragons...
harry d brown jr
Honored Contributor

Re: echo and backslash characters


How do you assign the value of ATTLINE ?? Maybe you can correct the issue there?

live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: echo and backslash characters


One option is to use the octal equivalent \0134 for the backslash.

e.g.
ATTLINE="\0134\0134Yes\0134"
echo "${ATTLINE}"

P.S. The backslashes may be silently swallowed by the
Webserver engine so each of the 0134's should be preceded by a backslash character.



If it ain't broke, I can fix that.
Adrian Brown_1
New Member

Re: echo and backslash characters

Hi,

Thanks for the replies.

The ATTLINE variable is being read from a file so I can't control what characters it contains.

However, Rod's suggestion worked !

Many thanks,

Adrian.
A. Clay Stephenson
Acclaimed Contributor

Re: echo and backslash characters

Well, if it's begin read from a file then it's even simpler:

cat ${ATTFILE} >> ${TEMPFILENAME}

there is no need for echo at all.
If it ain't broke, I can fix that.