[SGVLUG] Shell quoting
Matt Campbell
dvdmatt at gmail.com
Mon Apr 19 09:48:06 PDT 2010
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