Q: sh: Can I quote '"' in a double quoted string?

Q: sh: Can I quote '"' in a double quoted string?

Post by Laird Nels » Tue, 29 Oct 1996 04:00:00



I'm trying to reconcile some Bourne shell documentation (Solaris) with
Bourne shell's behavior.

The manpage says, regarding quoting:

"Inside a pair of double quote makrs (""), [...] \ quotes the
characters \, `,  , and $.  The pair \newline is removed before
parameter and command substitution.  If a backslash precedes
characters other than \, `,  , $, and newline, then the backslash
itself is quoted by the shell."

Note particularly the last sentence.  This would suggest that:

$ echo "   \" HELP! \"   "

...would give you:

   \" HELP! \"

...as output, right?  This would be because a double quote mark is not
one of those characters which a backslash quotes, according to the
documentation.  This seems like a load of hooey to me, because
everyone knows that if you type the example above you really get:

   " HELP! "

...instead.

OR: is it possible that what's going on here is the following:

1. The string consisting of three spaces, '\"', one space, 'HELP!',
one space, '\"', three spaces is quoted by the shell.  Since there are
no backslashed \, `,  , or $ characters, the shell protects the
whitespace and passes the string as one argument to the echo command.
Thus, echo gets
<space><space><space>\"<space>HELP!<space>\"<space><space><space> as
its sole arguement.

2. The subshell that echo is running under does processing on the one
argument to echo, translating the '\"' sequences to '"'.

Unless I hear otherwise, I'm going to assume that you CAN backslash a
double quote mark inside a double quoted string in the Bourne shell,
and that the documentation is simply wrong not to mention this.

Cheers,
Laird

--
laird j. nelson                                           (617) 252-5147

nets, incorporated                                       25 first street
http://www.amherst.edu/~ljnelson                     cambridge, ma 02141

 
 
 

Q: sh: Can I quote '"' in a double quoted string?

Post by Brian S Hil » Wed, 30 Oct 1996 04:00:00


: I'm trying to reconcile some Bourne shell documentation (Solaris) with
: Bourne shell's behavior.
: The manpage says, regarding quoting:
: "Inside a pair of double quote makrs (""), [...] \ quotes the
: characters \, `,  , and $.  The pair \newline is removed before
: parameter and command substitution.  If a backslash precedes
: characters other than \, `,  , $, and newline, then the backslash
: itself is quoted by the shell."
: Note particularly the last sentence.  This would suggest that:
: $ echo "   \" HELP! \"   "
: ...would give you:
:    \" HELP! \"
: ...as output, right?  This would be because a double quote mark is not
: one of those characters which a backslash quotes, according to the
: documentation.  This seems like a load of hooey to me, because
: everyone knows that if you type the example above you really get:
:    " HELP! "
: ...instead.
: OR: is it possible that what's going on here is the following:
: 1. The string consisting of three spaces, '\"', one space, 'HELP!',
: one space, '\"', three spaces is quoted by the shell.  Since there are
: no backslashed \, `,  , or $ characters, the shell protects the
: whitespace and passes the string as one argument to the echo command.
: Thus, echo gets
: <space><space><space>\"<space>HELP!<space>\"<space><space><space> as
: its sole arguement.
: 2. The subshell that echo is running under does processing on the one
: argument to echo, translating the '\"' sequences to '"'.
: Unless I hear otherwise, I'm going to assume that you CAN backslash a
: double quote mark inside a double quoted string in the Bourne shell,
: and that the documentation is simply wrong not to mention this.
: http://www.amherst.edu/~ljnelson                     cambridge, ma 02141

This is what my version of sh(1) man pages say (IRIX 5.2):

     If a backslash is used to escape a new-line character (\new-line), both
     the backslash and the new-line are removed (see the later section on
     "Quoting").  In addition, backslashes used       to escape dollar signs (\$)
     are removed.  Since no interpretation is done on the command string
     before it is read, inserting a backslash to escape a dollar sign has no
     effect.  Backslashes that precede characters other than \, `, ", new-
                                                                   ^
     line, and $ are left intact when the command string is read.

(Some nroffs convert dquotes not in a no-fill area, to two consecutive squotes.)

-Brian
--
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  

__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__

 
 
 

Q: sh: Can I quote '"' in a double quoted string?

Post by Christian Weisgerb » Wed, 30 Oct 1996 04:00:00



> Unless I hear otherwise, I'm going to assume that you CAN backslash a
> double quote mark inside a double quoted string in the Bourne shell,
> and that the documentation is simply wrong not to mention this.

Your assumption is correct.

--

  See another pointless homepage at <URL:http://home.pages.de/~naddy/>.
         -- currently reading: S. Andrew Swann, Revolutionary --

 
 
 

1. Double quotes within double quotes (no apostrophes)

Not what I want (although, of itself, it works):

RESULT=`echo all |grep "^$1"`
if [ "$RESULT" = "all" ] ; then

What I want:

if [ "`echo all |grep "^$1"`" = "all" ] ; then
     ^^^^^^^^^^^^^^^^^^^^^^^^

The carets, of course, indicate the problem i.e.
two sets of quoted text:

   "`echo all |grep "

and

   "'"

which is what I don't actually want.

Hope that's clear enough.

2. deleteing last line in all the files with certain name

3. quoted strings within quoted strings

4. Measuring memory usage

5. replace single quote to double quote with an example

6. Announcing the LUDE software library

7. Problem in sed using double quotes and single quotes

8. Affordable, Reliable & Dedicated Web Hosting

9. ? about single quote-double quote

10. REGULAR EXPRESSIONS; PERL/AWK/SED; SINGLE QUOTES/DOUBLE QUOTES

11. replace single quote to double quote with an example

12. Double quotes in 'csh'