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

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

Am 10.10.2009 um 11:33 schrieb Nazri Ramliy:
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 :)

You can’t prevent zsh from removing the quotes if you add them to the command line of your sql script, as far as I know.

But using the (q..) expansion flag you can re-add the quotes later.

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 %‘

In the sql script the word ‚Michael %‘ will end up in some variable, without the quotes. The script won’t even see that it was quoted before. If you expand this variable, add the (qq) flag.

I guess your main problem in this is that you’re using $* to simply pass all positional parameters of the script to the actual mysql command.

What you need is a mechanism that finds out which of those parameters should be single quoted (sql strings). Maybe it is enough if you quote all words that have a space in them, very roughly:

for a in $*
  if [[ -z ${a:#* *} ]]
    print ${(qq)a}
    print $a


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