Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
passing arg to function / alias
- X-seq: zsh-users 16138
- From: TJ Luoma <luomat@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: passing arg to function / alias
- Date: Sun, 17 Jul 2011 15:29:58 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=OVW3AlaZqgP8W1Y84QjDRsiQcTXkcRkW6hqPJ3HYNxs=; b=kFDCrGOkb6t4D5UEOFcQBDXZY+ux6IaIWwofi+jEshgP3TRiDZvFJX4thgo/lmtOYL sD3kfG7ToPAluZu56t9y+gCP/mPpdtZdoL7fzBl0VAR4ExEfbar+5avYy67GYt7Cjety lpGggkaixGWvz+zFm6GqHsmynGSWqzPtiOLoc=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
I am trying to figure out how to pass optional arguments to a shell
script and then have them be passed on to another program.
I'm not sure I can explain this well, so I'm going to try to
demonstrate what I mean with an example.
Imagine this is a program called 'list.zsh':
#!/bin/zsh -f
LS_ARG="-l"
case "$@" in
-j)
LS_ARG="-t -r $LS_ARG"
shift
;;
-z)
LS_ARG="-R -t $LS_ARG"
shift
;;
esac
eval /bin/ls ${LS_ARG} $@
exit 0
In this example, I want 'list.zsh' to ALWAYS do 'ls -l' but
* if I add '-j' I want it to do the equivalent of 'ls -l -t -r'
* if I add '-z' I want it to do 'ls -l -R -t'
Ideally, since /bin/ls has a lot of other flags, I would like to be
able to do this too:
./list.zsh -j -z -s /path/to/dir
and have "-s" just "passed along" to "/bin/ls" as another argument.
('list.zsh' is just for example purposes. I'm trying to figure out how
to do this same thing for several different programs, including curl
and lynx and others.)
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.
list.zsh pretty much only works if I don't give it any arguments or if
I just give it one of -z or -j. If I give it two (as in "list.zsh -j
-z" or even "list.zsh -z -S"), 'ls' complains that j/z are illegal
arguments.
Is this even possible?
If so, what am I doing wrong?
Thanks for your time.
TjL
Messages sorted by:
Reverse Date,
Date,
Thread,
Author