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

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



2009/10/11 DraÅen KaÄar <dave@xxxxxxxxxxxxxx>:
> 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.

Or you can just use double quotes instead.
sql "select * from foo where id = 'bar';"
or you can make sql read a line of input and do
sql
select * from foo where id = 'bar';
but of course, the whole point of the exercise was to have 'select' be an alias,
and maybe
select "* from foo where id = 'bar';"
looks weird?

I think an accept-line widget is really the only thing that could
work, but of course it will only work in simple commands, ie not for
things like echo $(for i in 1 2; do select foo) or something. (Unless
you reimplement all of zsh's parsing in the widget (not recommended)).

-- 
Mikael Magnusson



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