how to do multiple quotes

how to do multiple quotes

Post by Tolliver Johnny » Wed, 09 Mar 1994 01:48:13

Hmmm. Is this a shell question or a Motif window manager question? Maybe a
little of both, but here goes.

I need to launch an rsh process on another host, and I need to set an
environment variable for that process to use. Like this, using bash or ksh:

        rsh host "export VAR=something; xterm -e command"

where command is to be run on the remote host in an xterm window with display
back to the local display (although I've left out the -display for simplicity),
and command needs the value stored in the environment variable VAR.

The double quotes ensure that both commands -- i.e., the export and the xterm --
get run on the remote host.

The above works. But now suppose that VAR actually needs a value containing
spaces. For example, VAR="something -l". Then the following syntax works:

        rsh host "export VAR=\"something -l\"; xterm -e command"

Where quoting the inner " characters with \" does the needed trick.

Now suppose I want to package all this up as an f.exec entry in .mwmrc so I
can issue the above command with a mouse button in the root menu of an X

        f.exec  "stuff with spaces"

is the normal syntax. But how do I get the above stuff which already contains
double-quotes and quoted double-quotes into the f.exec?

This fails:

        f.exec "rsh host \"export VAR=\"something -l\"; xterm -e command\"

for the obvious reason that the second occurrence of \" terminates the first
rather than beginning another quoted string.

The bottom line question is how to do multiple embedded quotes in unix?
I haven't been on a VMS machine in years (and I'm glad) but it seems that back
in my VMS days that one could always just double the quotes to get quote a
quote -- i.e., "" to mean a single " if already inside a quoted string.

Is there some way to do this in unix? Yeah, of course I could package it all
up in a script and f.exec the script, but that's too kludgey and requires an
extra file -- the script -- so that editing the .mwmrc file might mean editing
two files. Messy. I'm looking for an elegant solution, all in one file.


Johnny Tolliver
Oak Ridge National Laboratory


1. sed append with multiple quotes.

I have figure out how to append and insert several lines of text into a script, however part

of the text is being eaten by the shell. I am trying to escape the concerned quotes but it

does not seem to work:

sed '/^\# hook - This is a hook/a\

if [ "$nt" = "true" ] && [ "$new_template" != "" ]; then \
      eval echo $2 '"$'$2'"' >> $new_template \
fi \ ' script > new_script

The problem is with the eval line, I need it to go into the script exactly as it appears,

but I am getting this:

eval echo $2 $'' >> $new_template

So I have started escaping the qoutes and got this far:

sed '/^\# hook - This is a hook/a\
    if [ "$nt" = "true" ] && [ "$new_template" != "" ]; then \
      eval echo $2 '\"$\'\$2\'\"' >> $new_template \
    fi \
    } ' script > new_script

Which almost gets me there, all I am missing now is the single ', I tried to escape these but it screws

the sed up. I even tried double escaping but to no avail. Any help appreciated.

eval echo $2 "$'$2'" >> $new_template - Just missing the last outside single quotes.



2. Patch Cluster Problem

3. bash : shell var, quoting multiple cmds, and 'su'

4. Re : netscape server for Sun ( non profit & educational program )

5. how to do multiple quotes

6. Window Maker won't start

7. Quotes in quotes

8. Konquerror..

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

10. replace single quote to double quote with an example

11. quoted strings within quoted strings

12. Quoting quotes in m4?

13. Double quotes within double quotes (no apostrophes)