From: Kenny McCormack on
In article <8aoumsFvcrU2(a)mid.individual.net>,
Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>On 2010-07-21, Kenny McCormack wrote:
>> In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d(a)speakeasy.net>,
>> John DuBois <spcecdt(a)armory.com> wrote:
>> ...
>>> Unless you specifically want to read from the controlling tty rather than
>>> the standard input, it's always better to save the standard input to
>>> another fd and then read from it.
>>>
>>> {
>>> commandThatGeneratesTheFilenames |
>>> while read x <&4; do
>>> cmd1
>>> cmd2
>>> cmd3
>>> done 4<&0 0<&3
>>> } 3<&0
>>
>> What's the difference between enclosing the cmds in {} vs. ()?
>
> Commands in ( ) are executed in a subshell.

That's what I thought. So, the answer to the original question, despite
all the other flurry, is simply: Yes, you should use {} rather than ().

--
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy of the church so decides."

- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -

From: Thomas 'PointedEars' Lahn on
Kenny McCormack wrote:

> Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>> On 2010-07-21, Kenny McCormack wrote:
>>> What's the difference between enclosing the cmds in {} vs. ()?
>> Commands in ( ) are executed in a subshell.
>
> That's what I thought. So, the answer to the original question, despite
> all the other flurry, is simply: Yes, you should use {} rather than ().

No, the answer simply is, again, "it depends." That is the part of software
development that you do not seem to understand.

--
PointedEars
From: Chris F.A. Johnson on
On 2010-07-21, John DuBois wrote:
> In article <i243tu$l8g$1(a)news.xmission.com>,
> Kenny McCormack <gazelle(a)shell.xmission.com> wrote:
>>In this group, it is an FGA that one should so:
>>
>> commandThatGeneratesTheFilenames | while read x ...
>>
>>instead of the more common:
>>
>> for i in ...
>>
>>because of the problems of filenames that spaces and other weird characters.
>>
>>However, one downside to the "while" method is that inside the loop,
>>stdin is now coming from the pipe, and commands that we execute inside
>>the loop, that expect a normal stdin, will misbehave.
>>
>>Workarounds:
>> 1) append "< /dev/tty" to each command
>> 2) enclose the commands in parens and redirect that. I.e.:
>>
>> commandThatGeneratesTheFilenames | while read x;do
>> (cmd1;cmd2;cmd3;...) < /dev/tty
>> done
>>
>>Method 2 is nice and seems to work fine, but I am wondering if there is
>>any hidden cost to it and if there is any more elegant/effcient way to
>>do this.
>
> Unless you specifically want to read from the controlling tty rather than
> the standard input, it's always better to save the standard input to
> another fd and then read from it.

Why?

> {
> commandThatGeneratesTheFilenames |
> while read x <&4; do

That will fail on filenames beginning or ending with spaces.

while IFS= read -r x <&4

> cmd1
> cmd2
> cmd3
> done 4<&0 0<&3
> } 3<&0
>
> In modern shells (ksh93/bash/zsh) you can do:
>
> while read -u3 x; do
> cmd1
> cmd2
> cmd3
> done 3< <(commandThatGeneratesTheFilenames)
>
> John


--
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)

From: Kenny McCormack on
In article <4540035.MirdbgypaU(a)PointedEars.de>,
Thomas 'PointedEars' Lahn <usenet(a)PointedEars.de> wrote:
>Kenny McCormack wrote:
>
>> Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>>> On 2010-07-21, Kenny McCormack wrote:
>>>> What's the difference between enclosing the cmds in {} vs. ()?
>>> Commands in ( ) are executed in a subshell.
>>
>> That's what I thought. So, the answer to the original question, despite
>> all the other flurry, is simply: Yes, you should use {} rather than ().
>
>No, the answer simply is, again, "it depends." That is the part of software
>development that you do not seem to understand.

You funny.

(And I've not even seen any pix of you and you funny ears!)

--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.

From: Seebs on
On 2010-07-21, Thomas 'PointedEars' Lahn <PointedEars(a)web.de> wrote:
> No, the foregone assumption (FGA is not a common Usenet acronym

"Frequently Given Answer", used by some guy whose name I've forgotten
to refer to things he maintains in a format chosen to prevent people from
rebutting the idiocy therein.

-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!