Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: noquote for quotes as in noglob for filename generation?



On Sat, Oct 10, 2009 at 11:30 AM, Philippe Troin <phil@xxxxxxxx> wrote:
> I don't see why you need eval or noglob here...
> What's wrong with replacing:
>
>        sql_command=`noglob echo "$@"`      # Note the noglob!
>        eval mysql -u $username -p$password $db "\"$sql\""
>
> with simply:
>
>        mysql -u $username -p$password $db "$*"
>
> ?

Nothing's wrong with it and it's actually simpler and better.  The two lines
are just old artifacts.

> The mechanism you want is:
>
>  ${(q)variable}    # Escaped
>  ${(qq)variable}   # Single quoted
>  ${(qqq)variable}  # Double quoted

Thank you Philippe for the tip (I learned something new). But I don't
think that's what I want here (or maybe I'm just too stupid to see how I
can make use of it to do what I want :)

What I want is for the script to receive the quotes that I gave it from
the command line 'unscathed'.

For example, if I ran:

   $ sql select * from Artist where first_name like 'Michael %'

I want the script to run this:

   mysql -u $user -p$password $db -e "select * from Artist where
first_name like 'Michael %'"

but instead what the script run is:

   mysql -u $user -p$password $db -e "select * from Artist where
first_name like Michael %"

which is wrong in SQL parlance because of the missing quote around "Michael %".

Right now I have to escape the single quotes:

   $ sql select * from Artist where first_name link \'Michael %\'

which is quite cumbersome as it is distracting to my train of thought
when building the sql command.

I'm thinking of doing something in preexec() to achieve this but that
seems a bit overkill for
that single shell script.

While we're on this topic I wonder if it would also possible to do
something similar for
parenthesis as well but that might be asking for too much.

Nazri.



Messages sorted by: Reverse Date, Date, Thread, Author