Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!att!cbnewsl!mpl From: mpl@cbnewsl.ATT.COM (michael.p.lindner) Newsgroups: alt.sources Subject: Re: Path Program Summary: passing args in shell Message-ID: <856@cbnewsl.ATT.COM> Date: 20 Jun 89 15:08:56 GMT References: <2912@csd4.milw.wisc.edu> <720@censor.UUCP> Distribution: na Organization: AT&T Bell Laboratories Lines: 62 In article <720@censor.UUCP>, markk@censor.UUCP (Mark Keating) writes: > > I also recieved a script, and one was posted as well to do the > same thing with the exception that path entries located are > not conditionally passed through `ls', which I find very useful > > The thing I liked about the one script was to specify the path, BUT since > everything that is an option, is blindly passed to ls for simplicity, > anybody have a good suggestion on the best way to handle this ?? simple! Here's the revised script: options= while [ "$#" -gt 0 ] do case "$1" in --) shift break ;; -*) options="$options $1" shift ;; *) break ;; esac done IFS=":$IFS" case "$#" in 0) echo >&2 "usage: $0 file [path ... ]" exit 1 ;; 1) file="$1" shift for d in $PATH do if [ -s $d/$file ] then /bin/ls$options $d/$file exit 0 fi done ;; *) file="$1" shift for d in $* do if [ -s $d/$file ] then /bin/ls$options $d/$file exit 0 fi done ;; esac echo >&2 "$0: $file not found" exit 1