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

Re: passing arg to function / alias

On Sun, Jul 17, 2011 at 5:42 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> "case" doesn't loop by itself, you need to call it inside one.

Oops! I actually knew that but neglected it in my example

> Also
> in zsh you probably want to use an array rather word splitting.
> Something like
>    local -a LS_ARG
>    while [[ $# -gt 0 && "$1" = -* ]]
>    do case "$1" in
>       -j) LS_ARG=(-t -r $LS_ARG);;
>       -z) LS_ARG=(-R -t $LS_ARG);;
>       *) LS_ARG=($LS_ARG $1);;
>       esac
>       shift
>    done
>    /bin/ls -l $LS_ARG $@

AHA! An array worked perfectly for me. Thanks!

> However, you might want to look at the "getopts" builtin if you want
> to write this in a POSIX-portable way, or at the "zparseopts" builtin
> for a zsh-specific alternative.

I decided to go "all in" on zsh for my scripting, so I'm not worried
about "portability" (not that it's not a bad goal, just one that I've
chosen not to worry about given finite resources of time and attention
and memory, since these are for personal use.)

That said 'zparseopts' has gone into my list of "ZSH Things To Learn"
but for now, arrays for everyone!



ps - sorry for the reply-delay. I've only now had a chance to go in
and try this. Where did July go? How is the summer almost over

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