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

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



Sebastian Stark wrote:
> 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.

I think he wants Perl quoting operators:


    Customary  Generic        Meaning        Interpolates
        ''       q{}          Literal             no
        ""      qq{}          Literal             yes
        ``      qx{}          Command             yes*
                qw{}         Word list            no
        //       m{}       Pattern match          yes*
                qr{}          Pattern             yes*
                 s{}{}      Substitution          yes*
                tr{}{}    Transliteration         no (but see below)
        <<EOF                 here-doc            yes*

        * unless the delimiter is ''.

So one could write "ordinary" quoting characters for other programming
languages, without quoting those characters in the zsh script source. That
would look like this:

   sql_execute q{select * from foo where id='bar';}

Since the pair 'q{', '}' encloses the string, one doesn't need to quote
apostrophes inside. Something like that would be useful, mostly because
"{}" can be replaced with any pair of delimiters, so one can pick
characters which are not used in the other language (SQL in this example).
The above example could also be written as:

   sql_execute q(select * from foo where id='bar';)

The minimal quoting syntax I managed to find in zsh is:

   setopt rc_quotes
   sql_execute 'select * from foo where id=''bar'';'

That's a bit more readable than id=\'bar\' but still requires quoting.

-- 
 .-.   .-.    Yes, I am an agent of Satan, but my duties are largely
(_  \ /  _)   ceremonial.
     |
     |        dave@xxxxxxxxxxxxxx



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