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

Re: Expansion order

Mads Martin Joergensen wrote:
> Hey together,
> $ export LS_OPTIONS="-N --color=tty -T 0"
> $ alias ls='ls $LS_OPTIONS'
> $ ls
> /bin/ls: invalid option --
> Try `/bin/ls --help' for more information.
> How come the zsh is doing the expansion in this case differently from
> csh, tcsh, bash and sh?

It's sh_word_split again.  You're using $LS_OPTIONS as a single word and
zsh is obliging.  The error message is confusing.

There are various possibilities:

alias ls="ls $LS_OPTIONS"

is the simplest, but if you want changes in LS_OPTIONS to be reflected
later on you need something else.

alias ls='ls $=LS_OPTIONS'

is the obvious.

More sophisticated:

typeset -xT LS_OPTIONS="-N --color=tty -T 0" ls_options
alias ls='ls $ls_options'

This allows for whitespace characters in the options as long as you
manipulate them through the array ls_options.

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.


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