<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<title>Re: Thanks for bash -c puzzle</title>
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Thanks Don,<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I came to the same realization earlier today. Rae actually
came up with a single-level solution:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>echo ‘command’ | bash<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>instead of<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>bash -c ‘command’<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>but echo runs into the same quoting quotes problem.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The full solution ended up being:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>echo -e "echo 'ALTER TABLE \\\0140Components\\\0140 ORDER
BY
\\\0140type\\\0140,\\\0140Home\\\0140,\\\0140Class\\\0140,\\\0140Make\\\0140,
\\\0140Model\\\0140,\\\0140Name\\\0140;ALTER TABLE \\\0140Documents\\\0140
ORDER BY \\\0140type\\\0140,\\\0140Year\\\0140,\\\0140Make\\\0140,\\\0140Version\\\0140,\\\0140Line\\\0140;ALTER
TABLE \\\0140Layouts\\\0140 ORDER BY \\\0140Date\\\0140;' | mysql -u 'matts'
'mattsInfo' -p'password' -h 'dbhost' " | /bin/bash 2>&1<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>-e allows bash-echo to interpret backslashed octal characters
which lets you embed quotes in your strings.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>It is being generated programmatically so the command is hidden
from the casual user.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Ok it’s ugly, at least it works…. ;)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Matt<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Gibbs, Donald E
(316B) [mailto:donald.e.gibbs@jpl.nasa.gov] <br>
<b>Sent:</b> Monday, April 19, 2010 3:12 PM<br>
<b>To:</b> Matt Campbell<br>
<b>Subject:</b> Re: Thanks for bash -c puzzle<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif"'>Hi, Matt<br>
<br>
You know, I followed Rae’s comment into the man pages for bash, down in
the “QUOTING” section, and it seems pretty clear that you cannot
put single quotes within other single quotes. Period. Backslashes
won’t help. Looks like the shell simply does not support what would
otherwise seem like a reasonable construction.<br>
<br>
You can put double quotes within other double quotes using backslashes.
But not so with single quotes.<br>
<br>
I’ll nose around some more, but it looks pretty cut and dried to
me.<br>
<br>
--Don<br>
<br>
<br>
On 4/19/10 10:44 AM, "Matt Campbell" <<a href="dvdmatt@gmail.com">dvdmatt@gmail.com</a>>
wrote:</span><o:p></o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif"'>Thanks Don, let me know if you come up with
anything.<br>
<br>
The base problem is ‘How do you quote a quote in shell’?<br>
<br>
The smallest test case is:<br>
<br>
echo '\'hi\' '<br>
<br>
I think it should produce: 'hi'<br>
<br>
It does produce: Unmatched '.<br>
<br>
They sure look matched to me. This fails the same way in tcsh and bash on
my Linux box.<br>
<br>
Matt<br>
<br>
<br>
</span><b><span style='font-size:10.0pt;font-family:"Calibri","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Calibri","sans-serif"'> Gibbs, Donald E
(316B) [<a href="mailto:donald.e.gibbs@jpl.nasa.gov">mailto:donald.e.gibbs@jpl.nasa.gov</a>]
<br>
<b>Sent:</b> Monday, April 19, 2010 10:37 AM<br>
<b>To:</b> Matt Campbell<br>
<b>Subject:</b> Re: Thanks for bash -c puzzle<br>
</span><br>
<span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Rae
Yip’s quote from the bash man page did not sound promising. I
can’t spend too much time on this, I’ve got other pressing
deadlines looming, but I’ll poke around at it.<br>
<br>
--Don<br>
<br>
On 4/19/10 10:29 AM, "Matt Campbell" <<a href="dvdmatt@gmail.com">dvdmatt@gmail.com</a>>
wrote:<br>
The problem can be simplified down to:<br>
<br>
This works:<br>
ssh -lmatt scar '/bin/bash -c "echo works" '<br>
<br>
No variation of this appears to:<br>
ssh -lmatt scar '/bin/bash –c \'echo fails\' '<br>
<br>
The only difference is mixed quotes vs. quoted quotes. Do you see a solution?<br>
<br>
I want to force bash on the far end so that shell redirection can be used to
capture error output back to the local host.<br>
<br>
All the rest of the (much more complex) command works.<br>
<br>
Matt<br>
<br>
<br>
</span><b><span style='font-size:10.0pt;font-family:"Calibri","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Calibri","sans-serif"'> Gibbs, Donald E
(316B) [<a href="mailto:donald.e.gibbs@jpl.nasa.gov">mailto:donald.e.gibbs@jpl.nasa.gov</a>]
<br>
<b>Sent:</b> Monday, April 19, 2010 10:15 AM<br>
<b>To:</b> Matt Campbell<br>
<b>Subject:</b> Thanks for bash -c puzzle<br>
</span><br>
<span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Hi, Matt<br>
<br>
I used to be more active in SGVLUG years ago but have become a mere lurker
lately.<br>
<br>
Thanks for asking about that bash question. I just started
re-strengthening my shell scripting skills and your problem was timely.<br>
<br>
Not that I could answer your question, but it made some of the bash man page
become more 3D, if you know what I mean.<br>
<br>
--Don</span> <o:p></o:p></p>
</div>
</div>
</body>
</html>