zsh-users
 help / color / mirror / code / Atom feed
* passing arg to function / alias
@ 2011-07-17 19:29 TJ Luoma
  2011-07-17 21:42 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: TJ Luoma @ 2011-07-17 19:29 UTC (permalink / raw)
  To: Zsh Users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-08 20:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-17 19:29 passing arg to function / alias TJ Luoma
2011-07-17 21:42 ` Bart Schaefer
2011-08-08 20:34   ` TJ Luoma

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).