From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 981 invoked by alias); 22 Feb 2012 23:51:27 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16782 Received: (qmail 29955 invoked from network); 22 Feb 2012 23:51:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at internecto.net designates 176.9.245.29 as permitted sender) X-Virus-Scanned: Debian amavisd-new at mx1.internecto.net Date: Wed, 22 Feb 2012 23:41:01 +0000 From: Mark van Dijk To: zsh-users@zsh.org Subject: Re: somehow offtopic: looping filenames In-Reply-To: <87k43g8g2c.fsf@ft.bewatermyfriend.org> References: <20120220181650.GA11514@solfire> <120220110530.ZM450@torch.brasslantern.com> <20120221123536.GF23815@new.computing.dcu.ie> <87k43g8g2c.fsf@ft.bewatermyfriend.org> Reply-To: mark+list@internecto.net Organization: Internecto SIS X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.10; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-Id: <20120222234236.A3A7E2981A8@mx1.internecto.net> Hi, > There is nothing about this, that would improve the behaviour of a > simple for loop like >=20 > for i in *; flac -- $i >=20 > (That's `short_loops' syntax, which is on by default in zsh. And it > relies on `sh_word_split' being unset, which is also the default > behaviour in zsh.) I agree to this. Also it's nice to pass a variable without being required to always specify it as ${foobar[@]}. Even better: to remind myself of the fact that a for loop often deals with arrays I became used to the following syntax: for i (*) echo $i and for i ($foobar) { command1; command 2 || print "command 2 failed!" } and if [[ -n $foo ]] { bar } else { baz } These are arbitrary examples of course; my point is that this syntax makes scripts more readable to me than the agonising if foo then bar else baz fi Especially with vim that highlights the opposite char ({) when you move to the original char (}). > Worse, it's *less* robust, because it's treating newline characters > specially, although they are perfectly legal characters in a file name > (albeit not very common ones). Also, if the user has an alias in > place, like say, >=20 > alias ls=3D'ls -F' >=20 > ...that is not going to work either, because that will cause ls to > append a / to directory names, a * to executable files and so on. I remember trying to use aliases in a script. I don't think this works, I changed them to functions at least. But yes I do agree on this, here it even became a sport to minimise the use of external commands as much as possible. With zsh these tasks are often trivial. I suppose we all love examples that show zsh's power and what I found great is that even sed and awk can easily be replaced:=20 cat $foobar | sed 's,Alice,Bob,g') versus ${foobar/Alice/Bob} (yes, bash can do this, too) cat /proc/sys/kernel/version | awk '{print $2}' versus ${$( I know there are HOWTOs and tutorials online, that advocate constructs > like that. And even worse ones, like "for i in `ls`; do...". But that > doesn't make them good examples of shell programming. Awfully written shell scripts have this much too often. > I don't mean to offend with this reply. And I hope that my point is > making sense to you. I've written about this in the past=C2=B2 (but it's = in > German) and so has the guy who maintains the FAQ for #bash (the IRC > channel for GNU bash on freenode)=C2=B3. Refer that that for more details > on parsing the output from `ls'. Additionally - it's a bit odd to prefer anything else above zsh's own powerful globbing abilities. I have used 'ls -dl /proc/**/*keyword*(.)' so often. I've often wondered if there is a Linux distribution using zsh as its default shell for users and distribution specific stuff like init scripts. I found your email nice to read, Frank. Ciao, -Mark.