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

Re: passing arg to function / alias



On Jul 17,  3:29pm, TJ Luoma wrote:
} Subject: passing arg to function / alias
}
} I thought that if I looped through the arguments using 'case' and
} appended each argument to the variable 'LS_ARG' then:
} 
} The results are pretty terrible.

"case" doesn't loop by itself, you need to call it inside one.  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 $@

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.



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