[SGVLUG] Shell quoting

Rae Yip rae.yip at gmail.com
Mon Apr 19 09:58:22 PDT 2010


Yeah. Matt's first example with bash -c makes it even more confusing
because of the extra layer of parsing.

If he's not supposed to create files on the remote host, he can still
send input via stdin over ssh, but that's going to have interesting
failure modes if it's interrupted partway through.

-Rae.

On Mon, Apr 19, 2010 at 9:53 AM, Dan Kegel <dank at kegel.com> wrote:
> That quoting is heinous indeed, no wonder you didn't get it right first try.
>
> My preference when faced with this kind of situation is to write a file
> and run that (in this case, you'd have to scp the file over).
> That lets me remove one layer of quotes,
> which can really reduce the insanity.
>
>
> On Mon, Apr 19, 2010 at 9:50 AM, Matt Campbell <dvdmatt at gmail.com> wrote:
>> Really sorry for all the typos, that's what I get for 2 hours of sleep.  ;)
>>
>> The correct command should have read:
>>
>> 'ssh -l<user> <isp shell host> \'mysql -u<database user> <database name> -p
>> <database password> -h <isp sql host> \\\'ALTER TABLE \\\`Layouts\\\` ORDER
>> BY \\\`Date\\\`;\\\'\' '
>>
>> Matt
>>
>>> -----Original Message-----
>>> From: Matt Campbell [mailto:dvdmatt at gmail.com]
>>> Sent: Monday, April 19, 2010 9:48 AM
>>> To: 'SGVLUG Discussion List.'
>>> Subject: RE: [SGVLUG] Shell quoting
>>>
>>> Hi Dan,
>>>
>>> Trying to run a SQL statement on my web server reqmotely.  The SQL
>>> engine is protected to localhost only so I have to ssh to the host to
>>> run the SQL.
>>>
>>> I am trying to write a generic execute function for future project.  I
>>> don't want to assume what the default shell is locally or remotely.
>>>
>>> The whole command that does not work is:
>>> 'ssh -l<user> \'<isp shell host> mysql -u<database user> <database
>>> name> -p <database password> -h <isp sql host> \\\'ALTER TABLE
>>> \\\`Layouts\\\` ORDER BY \\\`Date\\\`;\\\'\' '
>>>
>>> I have played with a couple dozen versions of quoting the quotes to no
>>> avail.  I do not want to mix quotes (which works) as I need to be able
>>> to programmatically quote all types of quotes in the arbitrary command
>>> passed to this function.
>>>
>>> Thanks for looking at it!
>>>
>>> Matt
>>>
>>>
>>> > -----Original Message-----
>>> > From: sgvlug-bounces at sgvlug.net [mailto:sgvlug-bounces at sgvlug.net] On
>>> > Behalf Of Dan Kegel
>>> > Sent: Monday, April 19, 2010 9:38 AM
>>> > To: SGVLUG Discussion List.
>>> > Subject: Re: [SGVLUG] Shell quoting
>>> >
>>> > On Mon, Apr 19, 2010 at 9:29 AM, Matt Campbell <dvdmatt at gmail.com>
>>> > wrote:
>>> > > Wow.  And I thought I knew my shell cold.
>>> > >
>>> > > Does anyone know the logic why this does not work?
>>> > >
>>> > >     matt at scar:166% bash -c 'echo \'ALTER TABLE\' '
>>> > >
>>> > >     Unmatched '.
>>> > >
>>> > > And how this is actually parsed?
>>> > >
>>> > >     matt at scar:144% bash -c echo 'ALTER TABLE `Components`'
>>> > >
>>> > >     (returns a blank line)
>>> >
>>> > What are you trying to do?  i.e. what do you want to appear in the
>>> > final output?
>>> > I guess you're generating a shell script that will generate SQL?
>>> >
>>> > - Dan
>>
>>
>


More information about the SGVLUG mailing list