quoted strings within quoted strings

quoted strings within quoted strings

Post by Richard Bauma » Fri, 24 Dec 1993 03:05:39



I need to send a character string which contains an embedded character
string to another host using the rsh command.  The argument of the rsh
command must itself be enclosed in quotes.  My code (which must be csh
code) is the following:#

    rsh usdbs 'echo "select * from view_ae where protocol = ?G8808?" | isql dictionary'

where the question marks around the G8808 character string are place-
holders for a third level of delimiter.  I've tried to use the escape
symbol (\) in various locations with no luck.  Because the command line
is actually issued from within an application program, it must be a
one-liner and must be C-shell.

Does anyone know how to do this?  Thanks in advance.

RLB

 
 
 

quoted strings within quoted strings

Post by Jeremy Mathe » Tue, 28 Dec 1993 09:35:08



Quote:>I need to send a character string which contains an embedded character
>string to another host using the rsh command.  The argument of the rsh
>command must itself be enclosed in quotes.  My code (which must be csh
>code) is the following:#

You can always do it, using the trick that to get a literal quote of one
kind, you enclose it in the quotes of the other kind.  So, you end up
with sequences of differeing quotes - it is confusing, but it can be done.

For example, here is an alias from my .cshrc:

alias M '(echo set noglob;echo "foreach i (\!:1-)";echo mmv -v '"'"'"'"'"'\$i'"'"'"'"'"' '"'"'"'"'"'\!$'"'"'"'"'"';echo end) | csh'

(Explanation available upon request...)

************************************************************************
"The rich are different from you and me."
                - Fitzgerald -
"Yes.  They have more money."
                - Hemmingway -


          hundreds, if not thousands, of dollars, every time he posts -
************************************************************************
rwvpf wpnrrj ibf ijrfer

 
 
 

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

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

2. Can't download e-mail with Word/Excel attachments

3. Regex searches within quoted strings

4. Linux Kernel Size, POSIX, Embedded

5. Double quotes within double quotes (no apostrophes)

6. FreeSCO and Thinkpad 701C & PCMCIA CDROM

7. sending quoted strings to CGI

8. SMB and IP masquerading

9. Preserving quoted strings and literal metacharacters in lists

10. How can you find a string within a string?

11. How To Substitute (with sed) Only in Quoted Part of String?

12. Single Quote part of a string

13. String containing double quotes