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

passing arg to function / alias



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