Re: Get the parameter pattern from command line

Alvin SIU wrote:

> When I issue the following :
> viewfile.ksh a*

Well, probably a dirty trick (whose applicability in your case I don't
know), however it should not be too difficult to call it using 'a*' (with
single quotes) and do the expansion inside, eg

$ cat filter.sh
#!/bin/sh

filter=$1 # save filter
set -- $1 # set positional parameters

printf "Filter is %s\n" "$filter"
n=1
for i in "$ [at] "; do
printf "Argument %d is %s\n" "$n" "$i"
n=$((n+1))
done

$ ls a*
a b c d.txt a.sh a.txt
$ ./filter.sh 'a*'
Filter: a*
Argument 1 is a b c d.txt
Argument 2 is a.sh
Argument 3 is a.txt

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
PK [ So, 30 März 2008 18:59 ] [ ID #1932360 ]
Linux » comp.unix.shell » Re: Get the parameter pattern from command line

Vorheriges Thema: Re: Arithmetic expansion not POSIX compliant in ksh, bash, or zsh!
Nächstes Thema: Re: while /usr/bin/read