From owner-freebsd-questions@FreeBSD.ORG Wed Jun 16 00:14:44 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 30B4B1065670 for ; Wed, 16 Jun 2010 00:14:44 +0000 (UTC) (envelope-from aiza21@comclark.com) Received: from avmxsmtp3.comclark.com (avmxsmtp3.comclark.com [202.69.191.117]) by mx1.freebsd.org (Postfix) with ESMTP id BBF748FC14 for ; Wed, 16 Jun 2010 00:14:43 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiYaAOuzF0zKRa1bPGdsb2JhbAAHh2iXFgEBAQE1J8EnhRoEg00 X-IronPort-AV: E=Sophos;i="4.53,423,1272816000"; d="scan'208";a="4013837" Received: from unknown (HELO [10.0.10.3]) ([202.69.173.91]) by avmxsmtp3.comclark.com with ESMTP; 16 Jun 2010 08:14:42 +0800 Message-ID: <4C18176E.7030008@comclark.com> Date: Wed, 16 Jun 2010 08:14:38 +0800 From: Aiza User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: "questions@freebsd.org" References: <4C173909.1050101@comclark.com> <4C174283.9090903@comclark.com> <20100615162505.GB31149@libertas.local.camdensoftware.com> In-Reply-To: <20100615162505.GB31149@libertas.local.camdensoftware.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: * wildcard in.sh script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2010 00:14:44 -0000 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*".