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

Re: [[ -x =command ]]



On Wed, Oct 17, 2007 at 10:44:14AM +0100, Stephane Chazelas wrote:
> zmodload -i zsh/parameters
> export PAGER=\
> ${commands[most]:-\
> ${commands[less]:-\
> ${commands[w3m]:-\
> ${commands[pager]:-\
> more}}}}
> 
> or, portably:
> 
> for PAGER in most less w3m pager more; do
>   command -v "$PAGER" > /dev/null 2>&1 && break
> done
> export PAGER
>   
> as I don't think you need the full path in $PAGER.

Hm.  `command -v more' and `$commands[more]' aren't equivalent, it
seems.

mastermind% echo $commands[ls]
/bin/ls
mastermind% command -v ls
alias ls='ls --color=auto -B'

So, just for the sake of argument, if one were to have aliased `most'
to `less' on a machine that didn't have most, the first form would
work properly, but the second would result in a false positive and
fail when an application tried to use $PAGER, since no alias expansion
would be performed.

~Matt



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