From: Ed Morton on 7 Feb 2010 14:12 On 2/7/2010 11:26 AM, Seebs wrote: > On 2010-02-07, Ed Morton<mortonspam(a)gmail.com> wrote: >> Writing a shell loop is something you >> should do after you've thought about whether or not it's really the best >> approach as it usually isn't > > Define "usually". The circumstances in which I find myself writing loops > in shell scripts are usually cases where I want to perform a series of > operations on each of several files, and while existing tools can often > perform a single operation on several files, trying to do them in a pipeline > seems doomed to failure. > > -s "usually" means "almost always unless you're creating/moving/removing multiple files and/or operating on multiple processes". Ed.
From: Seebs on 7 Feb 2010 14:27 On 2010-02-07, Ed Morton <mortonspam(a)gmail.com> wrote: > On 2/7/2010 11:26 AM, Seebs wrote: >> On 2010-02-07, Ed Morton<mortonspam(a)gmail.com> wrote: >>> Writing a shell loop is something you >>> should do after you've thought about whether or not it's really the best >>> approach as it usually isn't >> Define "usually". The circumstances in which I find myself writing loops >> in shell scripts are usually cases where I want to perform a series of >> operations on each of several files, and while existing tools can often >> perform a single operation on several files, trying to do them in a pipeline >> seems doomed to failure. > "usually" means "almost always unless you're creating/moving/removing > multiple files and/or operating on multiple processes". Ahh. See, since those are the circumstances in which I'm most likely to think to write a loop in a shell program, it turns out that, of cases in which I am thinking of writing a loop in shell, most often it is a good fit. The one exception I've had recently is that I wanted to generate some number sequences and, for various reasons, could not safely rely on the existence of any of the usual (jot, seq) candidates, so I did them as one-liner shell loops. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Chris F.A. Johnson on 8 Feb 2010 07:11 On 2010-02-07, Ed Morton wrote: > On 2/7/2010 11:26 AM, Seebs wrote: >> On 2010-02-07, Ed Morton<mortonspam(a)gmail.com> wrote: >>> Writing a shell loop is something you >>> should do after you've thought about whether or not it's really the best >>> approach as it usually isn't >> >> Define "usually". The circumstances in which I find myself writing loops >> in shell scripts are usually cases where I want to perform a series of >> operations on each of several files, and while existing tools can often >> perform a single operation on several files, trying to do them in a pipeline >> seems doomed to failure. >> >> -s > > "usually" means "almost always unless you're creating/moving/removing multiple > files and/or operating on multiple processes". I would interpret it to mean "unless you are operating on a [large] file". -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: Ed Morton on 8 Feb 2010 11:12 On Feb 6, 10:48 pm, Kaz Kylheku <kkylh...(a)gmail.com> wrote: > On 2010-02-07, Ed Morton <mortons...(a)gmail.com> wrote: > > > Note that in general if you find yourself writing a loop in a shell script, it's > > the wrong approach. > > On one recent project, I wrote not only a loop in a shell script, but in > fact a loop which reads input from a file, lexically analyzes, parses it > and interprets another language; a domain-specific language for > constructing a file system image with customized contents. Then that almost certainly took you longer to write and resulted in a less efficient, more error-prone, more complicated, and less extensible script than if you'd taken a different approach. Ed.
From: David Combs on 21 Feb 2010 20:11 In article <hkl7sf$ipv$1(a)news.eternal-september.org>, Ed Morton <mortonspam(a)gmail.com> wrote: .... .... >printf "Enter the number of values to be input: "; read numv; > >while (( counter < numv )) ^ -----^---- The extra paren-pair "hides" the "<" from being interpreted as a redirection? (Looks like it would.) Not that I know bash ("let"?) -- as bool, does "<" work on numbers, or must he use ".lt."? Silly questions -- maybe those "lets" gave me a concussion! David
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: find directory jpg and rename Next: is there a bash equivalent of "this" ... |