Date: Wed, 16 Jun 2010 08:14:38 +0800 From: Aiza <aiza21@comclark.com> To: "questions@freebsd.org" <questions@freebsd.org> Subject: Re: * wildcard in.sh script Message-ID: <4C18176E.7030008@comclark.com> In-Reply-To: <20100615162505.GB31149@libertas.local.camdensoftware.com> References: <4C173909.1050101@comclark.com> <4C174283.9090903@comclark.com> <20100615162505.GB31149@libertas.local.camdensoftware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Chip Camden wrote: > On Jun 15 2010 17:06, Aiza wrote: >> Aiza wrote: >>> I have a directory with files in it. The first 3 letters of the file >>> names is the group prefix. I'm trying to write a script to accept the 3 >>> letter of the group followed by a * to mean its a prefix lookup. But >>> when I run it I get a message "NO match" that is not issued by the >>> script. Its like * is not allowed as input. >>> >>> Looking for sample .sh code for handling this standard type of lookup or >>> some online tutorial that has sample code for bourne shell programming. >>> >> >> >> Here is the code >> >> prefix_name1=$1 >> prefix_name2=`echo -n "${prefix_name1}" | sed 's/*.*$//'` >> echo "prefix_name1 = ${prefix_name1}" >> echo "prefix_name2 = ${prefix_name2}" >> >> >> if [ ${prefix_name1} -nq ${prefix_name2} ]; then >> echo "prefix_name2 = ${prefix_name2}" >> fi >> exerr "hard stop" >> >> >> Here is the test and out put >> # >admin cell* >> admin: No match. >> > > As others have mentioned, you need to quote or escape the * in the > command line: > > admin "cell*" > > You've also botched your regex (/*.*$/) -- it can't begin with a *. What exactly > are you trying to match? > As shown in the posted test results you can see that the * is removed from the input cell* and becomes cell and then cell* is compared to cell to determine if a search by prefix command was entered on the script command line. So the regex (/*.*$/) is working as coded as long as the script command line is coded like this "cell*".
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C18176E.7030008>