From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1702 invoked from network); 28 Mar 2004 00:55:51 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 28 Mar 2004 00:55:51 -0000 Received: (qmail 29530 invoked by alias); 28 Mar 2004 00:55:35 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7272 Received: (qmail 29489 invoked from network); 28 Mar 2004 00:55:35 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 28 Mar 2004 00:55:35 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 28 Mar 2004 0:55:35 -0000 Received: (qmail 12313 invoked from network); 28 Mar 2004 00:55:35 -0000 Received: from wbar3.sjo1-4-11-009-147.sjo1.dsl-verizon.net (HELO candle.brasslantern.com) (4.11.9.147) by a.mx.sunsite.dk with SMTP; 28 Mar 2004 00:55:33 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i2S0tVS19874 for zsh-users@sunsite.dk; Sat, 27 Mar 2004 16:55:31 -0800 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040328005531.ZM19873@candle.brasslantern.com> Date: Sun, 28 Mar 2004 00:55:31 +0000 In-Reply-To: <20040325223228.GA13221@DervishD> Comments: In reply to DervishD "Is this the Zsh way for doing this?" (Mar 25, 11:35pm) References: <20040325223228.GA13221@DervishD> X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh Users Subject: Re: Is this the Zsh way for doing this? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: **** X-Spam-Status: No, hits=4.7 required=6.0 tests=RCVD_IN_DYNABLOCK, RCVD_IN_NJABL,RCVD_IN_NJABL_DIALUP,RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 4.7 On Mar 25, 11:35pm, DervishD wrote: } } tail +2 .CDinfo | while read song This is fine, but you might prefer the more obvious: tail +2 .CDinfo | while read ignored_word track_number track_name do # At this point ignored_word is always "Track" and track_number # still has a trailing colon that we need to strip off. Also # track_name contains single quotes, but based on this example: # Track 10: 'This song really doesn't exist...' # they aren't balanced single quotes, so we have to strip them. # If the zero-padding gets done here too, it's clearer later. track_number=${(l.2..0.)${track_number%:}} track_name=${${track_name%\'}#\'} # At this point you might also want to clean wildcards and slashes # out of $track_name, but that's up to you. Your original doesn't. # Now the "mv" command is quite obvious. mv audio_${track_number}.cdr "${track_number}.${track_name}.cdr" done If you really desperately want to write it all as one command rather than have the two extra assignments: mv audio_${track_number/ As to your specific pattern-matching questions: } ${song/#(#b)Track #([0-9]##):'(*)'/${(l.2..0.)match[1]}.${match[2]}}.cdr } } AFAIK, when pattern matching takes place } at the point of the "'(*)'", it is implicitly anchored to the end of } the string and is the longest match No, it's not implicitly anchored at the end, but it is the longest match, which (since there is always a single-quote at the end of the string) is equivalent in this case. However, you do need to escape the single quotes, and there is a space after the colon: (#b)Track #([0-9]##): \'(*)\' } [Why can't I] use the (#b) flag before the '/' (together with 'song') } or before the '#' (which indicates that 'Track' must match at the } beginning of the string) [...?] What you've asked is very similar to asking about C, Why can't I put the "--" before the "+" or before the "=" in the expression "song += --pattern" ? This is because the / and the # together constitute an operator on the value of the variable, whereas (#b) is part of the pattern which is an argument to that operator. } BTW, is that '#' necessary or not? It's not necessary as long as none of the names is "The Track 27: song" or some such. } Do I need to specify too the end of the string anchor? No.