From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27208 invoked from network); 6 May 2005 16:03:45 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 May 2005 16:03:45 -0000 Received: (qmail 58541 invoked from network); 6 May 2005 16:03:38 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 May 2005 16:03:38 -0000 Received: (qmail 11929 invoked by alias); 6 May 2005 16:03:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8787 Received: (qmail 11915 invoked from network); 6 May 2005 16:03:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 May 2005 16:03:30 -0000 Received: (qmail 57249 invoked from network); 6 May 2005 16:03:30 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 6 May 2005 16:03:26 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IG2009CGSLONSV8@vms044.mailsrvcs.net> for zsh-users@sunsite.dk; Fri, 06 May 2005 11:03:25 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j46G3Nk2032157 for ; Fri, 06 May 2005 09:03:24 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j46G3NmN032156 for zsh-users@sunsite.dk; Fri, 06 May 2005 09:03:23 -0700 Date: Fri, 06 May 2005 16:03:22 +0000 From: Bart Schaefer Subject: Re: passing parameters In-reply-to: To: zsh-users@sunsite.dk Message-id: <1050506160323.ZM32155@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <1050506035734.ZM31409@candle.brasslantern.com> Comments: In reply to zzapper "Re: passing parameters" (May 6, 1:54pm) X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On May 6, 1:54pm, zzapper wrote: > > cnt=$(ls **/*.tex |egrep -ic "$1[^/]*.tex" ) > texfile=$(ls **/*.tex |egrep -i "$1[^/]*.tex" ) [versus] > param="$1.*$2" > cnt=$(ls **/*.tex |egrep -ic "${param}[^/]*.tex" ) > texfile=$(ls **/*.tex |egrep -i "${param}[^/]*.tex" ) > > But why is it necessary to write ${param} ? and it wasn't necessary to > write ${1} $identifier[subscript] is an array expression. When $identifier is a scalar, it does character-wise indexing to extract substrings. "1" is not an identifier. $1 is a special case of expansion used for the positional parameters. So $1[anything] is not an array expression, it's the expression $1 followed by the string [anything]. Similarly, $1foo is ${1}foo because "1foo" is not an identifier, but "foo1" is an identifier so $foo1 is the same as ${foo1}. You can force indexing into $1 by ${1[subscript]}.