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

Re: Porting an alias from bash to zsh fails.



On Sat, 23 Oct 2004, s. keeling wrote:

> Hi list.  I'm new to zsh so this could well be pretty simple.  I've been 
> wondering why the following works in bash, but fails miserably in zsh.

It's almost certainly because the default setting of the NO_MATCH option
is reversed in the two shells.  In bash, by default, when a glob doesn't
match anything, the pattern is left unexpanded, but in zsh by default it
generates the "no matches" error.

> What am I missing here?

>    RXVTNEWSFONT='-*-neep alt-medium-*-normal-*-*-100-75-75-c-*-iso8859-1'
> 
>    alias dfn="rxvt +sb -fn $RXVTNEWSFONT -geometry 128x51+69+42 \
>       -e nice /usr/bin/slrn -f /home/keeling/.jnewsrc-dfn \
>       -h news.individual.net"

This one would have worked for you if only you'd put the entire thing in
single quotes instead of double quotes.  There's no reason to expand the
variable at the time the alias is defined; let it be expanded (and thus
not globbed) at the time the alias is _used_.  This has the added benefit
that you can change the value of the variable to change the font used by
the alias, without having to redefine the alias again.

On Sat, 23 Oct 2004, s. keeling wrote:

> Incoming from Lloyd Zusman:
> >    alias dfn="rxvt +sb -fn '$RXVTNEWSFONT' -geometry 128x51+69+42 \
> >       -e nice /usr/bin/slrn -f /home/keeling/.jnewsrc-dfn \
> >       -h news.individual.net"
> > [snip]
> > 
> > This works because the single quotes are treated as normal (non-quoting)
> .....................^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > characters when inside of double quotes; therefore, the RXVTNEWSFONT
> ..^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> That was a surprise to me.  Thanks.  Your excellent explanation has
> solved it for me.  Much appreciated.

Lloyd's suggestion works in this case, but it would fail in the event that
the value of the variable contained any single-quote characters.  A better
solution would be to swap the single and double quotes:

alias dfn='rxvt +sb -fn "$RXVTNEWSFONT" -geometry 128x51+69+42 ...'



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