For Programmers: Free Programming Magazines  


Home > Archive > AWK > April 2005 > OT: Unix shells and the single quote char (Was: Re: Why won't this AWK work to create









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author OT: Unix shells and the single quote char (Was: Re: Why won't this AWK work to create
Kenny McCormack

2005-04-10, 3:55 pm

In article <3brmmpF6hqjarU1@uni-berlin.de>,
Patrick TJ McPhee <ptjm@interlog.com> wrote:
>In article <ei2g5155c4guh15v04ckn1o13mpqr2lmns@4ax.com>,
>Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> wrote:
>% On 8 Apr 2005 03:00:49 GMT in comp.lang.awk, ptjm@interlog.com
>% (Patrick TJ McPhee) wrote:
>%
>% >Printing ' can be problematic in an awk script which is passed as an
>% >argument.
>%
>% Not too hard: just replace each embedded "'" with "'''".
>
>You could do this, but it won't solve the problem with the majority of
>Unix shells. It can be problematic.


No, the method is to replace each embedded ' with '"'"' (5 alternating
quote marks). I think what you (Patrick) are getting at is that methods
using \s are unreliable - and this agrees with my experience.

I just tested this shell command:

gawk 'BEGIN {print "'"'"'","is a single quote"}'

under tcsh, sh, and ksh - and got the same (correct) result each time.

Note that, for real life AWK/shell scripting, the \047 method is easier.
In the \047 method, the above would be written:

gawk 'BEGIN {print "\047","is a single quote"}'

P.S. The "5 quote" method is handy to know when writing csh aliases.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com