f



Fixing stdin inside a redirected loop...

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.

-- 
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

0
gazelle
7/20/2010 12:13:50 PM
comp.unix.shell 15443 articles. 2 followers. Post Follow

18 Replies
9305 Views

Similar Articles

[PageSpeed] 52

Kenny McCormack 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

I think (at least with bash) it's possible to use a file descriptor other 
than the standard ones, and use read -u to read from that descriptor. This 
way, standard descriptors (0, 1 and 2) inside the loop are not affected.

Something like

exec 3< <(command)

while read -u 3 line; do
  # unaffected commands here...
done

exec 3>&-


I understand it's a highly nonstandard solution, but, depending on where it 
has to run, it might be applicable.
0
pk
7/20/2010 12:55:19 PM
In article <i246br$vjs$1@speranza.aioe.org>, pk  <pk@pk.invalid> wrote:
....
>I think (at least with bash) it's possible to use a file descriptor other 
>than the standard ones, and use read -u to read from that descriptor. This 
>way, standard descriptors (0, 1 and 2) inside the loop are not affected.
>
>Something like
>
>exec 3< <(command)
>
>while read -u 3 line; do
>  # unaffected commands here...
>done
>
>exec 3>&-
>
>I understand it's a highly nonstandard solution, but, depending on where it 
>has to run, it might be applicable.

Very interesting.  As readers of my posts know, I'm not a "standards
jockey", so don't take what I say next as the typical SJ jockeying...

That said,
    1) The above works if I invoke "bash" as "bash".
    2) (However) It does not work if I invoke "bash" as "sh"
    3) It doesn't work under "dash" (which is what /bin/sh on some Linux
	boxes actually is).

Anyway, as I said, it is quite intriguing.

-- 
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

0
gazelle
7/20/2010 2:12:57 PM
In article <i24at9$rc5$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
....
>That said,
>    1) The above works if I invoke "bash" as "bash".
>    2) (However) It does not work if I invoke "bash" as "sh"
>    3) It doesn't work under "dash" (which is what /bin/sh on some Linux
>	boxes actually is).
>
>Anyway, as I said, it is quite intriguing.

I forgot to add, the important thing, which is that your solution,
unfortunately, does not work on the targetted system (which is a Linux
system without bash - yes, they exist).  So, I am still curious about
the questions raised in the OP - is there any hidden cost (inefficiency)
to using the ()</dev/tty method, and are there any (other) alternatives?

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

0
gazelle
7/20/2010 2:24:37 PM
On Tue, 20 Jul 2010 14:12:57 +0000 (UTC) gazelle@shell.xmission.com (Kenny
McCormack) wrote:

> In article <i246br$vjs$1@speranza.aioe.org>, pk  <pk@pk.invalid> wrote:
> ...
> >I think (at least with bash) it's possible to use a file descriptor
> >other than the standard ones, and use read -u to read from that
> >descriptor. This way, standard descriptors (0, 1 and 2) inside the loop
> >are not affected.
> >
> >Something like
> >
> >exec 3< <(command)
> >
> >while read -u 3 line; do
> >  # unaffected commands here...
> >done
> >
> >exec 3>&-
> >
> >I understand it's a highly nonstandard solution, but, depending on where
> >it has to run, it might be applicable.
> 
> Very interesting.  As readers of my posts know, I'm not a "standards
> jockey", so don't take what I say next as the typical SJ jockeying...
> 
> That said,
>     1) The above works if I invoke "bash" as "bash".
>     2) (However) It does not work if I invoke "bash" as "sh"
>     3) It doesn't work under "dash" (which is what /bin/sh on some Linux
> 	boxes actually is).

Standards jockey or not, if that is where it has to run, you definitely need
a standard solution.

0
pk
7/20/2010 5:06:56 PM
Kenny McCormack 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.

Name one, and I am pretty sure that I can tell you the switch that will 
prevent it from considering stdin.  For example, ssh(1) has `-n'.

-- 
PointedEars
0
Thomas
7/21/2010 12:14:38 AM
Kenny McCormack 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.

No, the foregone assumption (FGA is not a common Usenet acronym -- shouldn't 
that be "foregone conclusion" anyway?) is that find(1) with `-exec', or 
`find' with xargs(1), are safer than both approaches.

Usenet rule of thumb: Never ask what is better; bottom line is that better 
is what works for you.  Ask instead what is more efficient aso. given a 
specific context.

-- 
PointedEars
0
Thomas
7/21/2010 12:24:50 AM
In article <i243tu$l8g$1@news.xmission.com>,
Kenny McCormack <gazelle@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.

    {
	commandThatGeneratesTheFilenames |
	    while read x <&4; do
		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
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
spcecdt
7/21/2010 4:56:01 PM
In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d@speakeasy.net>,
John DuBois <spcecdt@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. ()?

-- 
Faced with the choice between changing one's mind and proving that there is
no need to do so, almost everyone gets busy on the proof. 

    - John Kenneth Galbraith -

0
gazelle
7/21/2010 5:45:28 PM
On 2010-07-21, Kenny McCormack wrote:
> In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d@speakeasy.net>,
> John DuBois <spcecdt@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.


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

0
Chris
7/21/2010 7:05:00 PM
In article <8aoumsFvcrU2@mid.individual.net>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2010-07-21, Kenny McCormack wrote:
>> In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d@speakeasy.net>,
>> John DuBois <spcecdt@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 -

0
gazelle
7/21/2010 7:10:05 PM
Kenny McCormack wrote:

> Chris F.A. Johnson <cfajohnson@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
0
Thomas
7/21/2010 8:59:14 PM
On 2010-07-21, John DuBois wrote:
> In article <i243tu$l8g$1@news.xmission.com>,
> Kenny McCormack <gazelle@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)

0
Chris
7/21/2010 9:30:36 PM
In article <4540035.MirdbgypaU@PointedEars.de>,
Thomas 'PointedEars' Lahn  <usenet@PointedEars.de> wrote:
>Kenny McCormack wrote:
>
>> Chris F.A. Johnson <cfajohnson@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.

0
gazelle
7/21/2010 9:34:20 PM
On 2010-07-21, Thomas 'PointedEars' Lahn <PointedEars@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@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
0
Seebs
7/21/2010 9:49:57 PM
Kenny McCormack wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Kenny McCormack wrote:
>>> Chris F.A. Johnson <cfajohnson@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.

It was not my intention to amuse you, but to make you think twice.  BTW, in 
responding like this you are also making a fool of yourself with regard to 
grammar.

> (And I've not even seen any pix of you and you funny ears!)
 
I have not seen a photo of you either.  So what?
-- 
PointedEars
0
Thomas
7/22/2010 12:31:09 AM
Seebs wrote:

> Thomas 'PointedEars' Lahn 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.

Thanks.  In ten years of regular Usenet participation, in and outside of the 
Big 8, I had never come across that acronym.  It is not in the Jargon File 
either.  So I doubt it is more than his original research.

-- 
PointedEars
0
Thomas
7/22/2010 9:44:28 AM
In article <8ap77sFvcrU3@mid.individual.net>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2010-07-21, John DuBois wrote:
>> In article <i243tu$l8g$1@news.xmission.com>,
>> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>>>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?

Because the standard input may not be the controlling tty (if the program is
piped or redirected into, or started from an environment with no controlling
tty, etc).

	John
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
spcecdt
7/22/2010 3:03:54 PM
2010-07-20, 12:13(+00), Kenny McCormack:
> 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.

After

IFS='
' # NL
set -f
for i in $(commandThatGeneratesTheFilenames); do...

shouldn't be a problem (except that the loop only starts when
commandThatGeneratesTheFilenames finishes).

Other solution (not any better either than the ones that have
already been given):

while IFS= read <&3 -r i; do
   ...
done 3<<EOF
$(commandThatGeneratesTheFilenames)
EOF

{
  commandThatGeneratesTheFilenames |
    while IFS= read <&3 -r i; do
      ...
    done 3<&0 <&4 4<&-
} 4<&0

as already given would be the best one. If you're picky, you may
write it:

{
  commandThatGeneratesTheFilenames 4<&- |
    while IFS= read <&3 -r i; do
    {
      ...
    } 3<&-
    done 3<&0 <&4 4<&-
} 4<&0

or:

{
  commandThatGeneratesTheFilenames 4<&- |
    while IFS= read -r i 4<&-; do
    {
      ...
    } <&4 4<&-
    done
} 4<&0

-- 
Stephane
0
Stephane
7/26/2010 4:57:51 PM
Reply:

Similar Artilces:

while loop inside a for loop
Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about. What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on. Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications. Many thanks in advance. A=[0 0 0 0 0 0 ...

Triple nested loop python (While loop insde of for loop inside of while loop)
try to make my triple nested loop working. My code would be: c = 4 y1 = [] m1 = [] std1 = [] while c <24: c = c + 1 a = [] f.seek(0,0) for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'nearest') p = interp(indices) N = len(p) dt = 900.0 #Time step (seconds) fs = 1./dt #Sampling frequency KA,PSD = oned_Fourierspectrum(p,dt) # Call Song's 1D FS function time_axis = np.linspace(0.0,N,num = N,endpoint = False)*15/(60*24) plot_freq = 24*3600.*KA #Convert to cycles per day plot_period = 1.0/plot_freq # convert to days/cycle fpsd = plot_freq*PSD d = -1 while d <335: d = d + 1 y = fpsd[d] y1 = y1 + [y] m = np.mean(y1) m1 = m1 + [m] print m1 -------------------------------------------------------------------------------- My purpose is make a list of [mean(fpsd[0]), mean(fpsd[1]), mean(fpsd[2]).. mean(fpsd[335])]. Each y1 would be the list of fpsd[d]. I check it is working pretty well before second while l...

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot;
I think I have a similar problem - I have a while loop with Flat Sequence controlled for loop that produces output. This output needs to be displayed every while loop pass, but I get no output as the while loop feeds back thru a shift register and repeats all the innner funcions without sending the ouput to form new entries in the array. &nbsp; Is there any way we could stop the while loop for a split second (but practically just for no time, so that no time is wasted when it outputs the data)? &nbsp; Or is it a bad approach altogether? &nbsp; Appreciate any advice. &nbsp; kolo...

timed loop inside a while loop
Hi all, I want to ask if I have a timed loop inside a&nbsp; while loop ,&nbsp; the timed loop&nbsp; does a certain task &nbsp;a 100 iteration ( each time loop iteration is 2 second duration)&nbsp;each while loop iteration &nbsp;, at each&nbsp; while loop iteration the time loop writes the actual time spent to a text file for this certain task. &nbsp; for the next while loop, the timed loop contiues&nbsp; to write the time spent from the previous while loop ( ex the first while loop the time loop ends the last results with 200 second for a 100&nbsp; time ...

looping inside string containing * / avoid shell expansion
hello, i'm new to linux shell, i would like to split a string like this one: TEST="apath/ anotherpath/*.txt" for d in $TEST do echo "$d" done here i wanted to output: >apath >anotherpath/*.txt btw i just can not avoid shell to expand '*.txt' to 'file1.txt', 'file2.txt'; etc. i think i am missing something around 'TEST' in 'for d in $TEST' but i have no clues... best, On Sat, 08 May 2004 09:39:49 -0700, Valia wrote: > hello, > > i'm new to linux shell, i would like to split a string like this one: &...

Any way to access an outside UNIX shell from inside firewall?
Sorry if this is off-topic. I have some free UNIX shell accounts at e.g. rootshell.be, cyberspace.org. But our company firewall only allows outbound access through HTTP and FTP ports (maybe plus a few others). I can't telnet or ssh to them. http://m-net.arbornet.org/login/ offers a Web-based Java applet for shell access. But that doesn't work either probably because the applet simply does a telnet. Is there a way to access those UNIX shells? Thanks. Yong Huang On Wed, 03 Mar 2004 16:17:50 -0800, Yong Huang wrote: > Sorry if this is off-topic. I have some free UNIX shell accounts ...

Putting the loop inside of loop properly
I just would like to make my previous question simpler and I bit adjusted m= y code with help with Ulich and Chris. The basic structure of my code is: for c in range(5,25): for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x =3D np.array(a, float) not_nan =3D np.logical_not(np.isnan(x)) indices =3D np.arange(len(x)) interp =3D interp1d(indices[not_nan], x[not_nan], kind =3D 'nearest= ') p =3D interp(indices) N =3D len(p) fpsd =3D plot_freq*PSD f.seek(0,0) for d in range(336): y =3D fpsd[d] y1 =3D y1 + [y] m =3D np.mean(y1) m1 =3D m1 + [m] ------------------------------------------------------------------ I just removed seemingly unnecesary lines. I expect that last loop can prod= uce the each order values (first, second,.... last(336th)) of fpsd from for= mer loop. fpsd would be 20 lists. So, fpsd[0] in third loop shoul be first values fro= m 20 lists and it expects to be accumulated to y1. So, y1 should be the lis= t of first values from 20 fpsd lists. and m is mean of y1. I expect to repe= at 356 times and accumulated to m1. However, it doesn't work and fpsd value= s in and out of the last loop are totally different. My question is clear? Any help or questions would be really appreciated. Isaac On 2013-03-01 18:07, Isaac Won wrote: &g...

speed up for loop inside for loop short question
Hi there, Given three column vectors x,y,z I want to calculate the probabilities: P(X<Y<Z), P(X=Y<Z), P(X<Y=Z), P(X=Y=Z). The following code gets the job done but I would like it to be faster. Is there a way of getting rid of at least one of the for loops? (I described the problem above instead of just giving the code because it might be helpful for someone to take a completely different approach, or check me (I think this is correct). Anyway if you are bored to check, any ideas regarding the speed would be more than welcome!). Thanx in advance for any answers! o...

can I run unix shell command in the ModelSim shell?
Hi, Just wonder if I can run unix shell command in the Modelsim shell, expecially those time/date command? Thanks. clinton__bill@hotmail.com wrote: > Hi, > Just wonder if I can run unix shell command in the Modelsim shell, > expecially those time/date command? ModelSim uses Tcl as its scripting language so (almost) anything you can do from Tcl can be done in ModelSim. Tcl has a variety of shell and file interaction commands available. Of course, if you want to execute Unix commands, you need to be running on a Unix (or Cygwin) system. Note that Tcl commands are NOT direct...

Nested parfor loop: Classification of Matrix inside loop
Hello, I am having problems with the following loop, since it is taking too much time. Hence, I would like to use parallel processing, specifically parfor function. Can anyone, please, help me to convert the following 'far' loop into 'parfor'? P = numel(scaleX); % quite BIG number sz = P; start = 1; sqrL = 10; % sqr len e = 200; A = false(sz, sz); parfor m = sz-sqrL/2:(-1)*sqrL:start for n = M(m):-sqrL:1 temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)]; d = pdist(temp, 'euclidean'); if d < e A(m, n) = 1; end end end Thank you! "Bek Abdik" <beknazar@unist.ac.kr> writes: > I am having problems with the following loop, since it is taking too > much time. Hence, I would like to use parallel processing, > specifically parfor function. > > Can anyone, please, help me to convert the following 'far' loop into 'parfor'? > > P = numel(scaleX); % quite BIG number > sz = P; > start = 1; > sqrL = 10; % sqr len > e = 200; > A = false(sz, sz); > > parfor m = sz-sqrL/2:(-1)*sqrL:start > for n = M(m):-sqrL:1 > temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)]; > d = pdist(temp, 'euclidean'); > if d < e > A(m, n) = 1; > end > end > end As the code analyzer message informs you, the range of a PARFOR l...

Nested parfor loop: Classification of Matrix inside loop #2
Hello, I am having problems with the following loop, since it is taking too much time. Hence, I would like to use parallel processing, specifically parfor function. Can anyone, please, help me to convert the following 'far' loop into 'parfor'? P = numel(scaleX); % quite BIG number sz = P; start = 1; sqrL = 10; % sqr len e = 200; A = false(sz, sz); parfor m = sz-sqrL/2:(-1)*sqrL:start for n = M(m):-sqrL:1 temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)]; d = pdist(temp, 'euclidean'); if d < e A(m, n) =...

redirecting Stdin
Hi Is is Possible to redirect the Python stdin in order to receive stdin commands from a file ? The time of redirection can last until exiting the Python and should be transparent for python it self. with regards Jon Jon Arter wrote: > Is is Possible to redirect the Python stdin in order to receive stdin > commands from a file ? > The time of redirection can last until exiting the Python and should > be transparent for python it self. Sure: sys.stdin = file('newinput') -- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ ...

Unix Shell
I'm new to RUBY, but am familar with other scripting languages, PHP, Perl, Wscript, etc. I'd like to be able to run items from the shell such as ls -l > dirlisting.txt. Just an example. Can I do this? I would have just used the search on these forums, but unfortuantely when I click Search I get "The page cannot be found". Hope they can get this fixed so I won't have to ask every little question. Thanks in advance. -Greg -- Posted via http://www.ruby-forum.com/. Greg Johnson wrote: > I'd like to be able to run items from the shell > such as l...

if loop in UNIX
Hi all, I have a doubt using IF loop in UNIX. I have the following statement. if [[ `cat /udb/db2enpid/clnpis/udb09/scripts/export_table_bluee_5/count_messages_begin_bluee|wc -l` != 10 ]] then > print -- "not equal" > else > print -- "equal" > fi not equal but when i do wc on the file it gives cat /udb/db2enpid/clnpis/udb09/scripts/export_table_bluee_5/count_messages_begin_bluee|wc -l 10 The result i want to get out of the if loop is equal. Can somebody help me please. Thanks in advance On 22 Nov 2006 06:53:33 -0800, chaitu wrote: > Hi all...

WHILE LOOP AS FOR LOOP
its possible? For each id in (SELECT * FROM table) INSERT INTO table2(id,fk,nombre) values(1,id,'xxx'); Jessica Gonz�lez (jess.rgm@gmail.com) writes: > its possible? > > For each id in (SELECT * FROM table) > INSERT INTO table2(id,fk,nombre) > values(1,id,'xxx'); > So in SQL, you don't normally code the loops explicitly - the loops are hidden on the inside. Logically, it is an operation of a set. INSERT table(id, fk, nombre) SELECT 1, id, 'xxx' FROM table -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx thanks.. but SET IDENTITY_INSERT table ON; INSERT INTO table(pk,activo,permiso,rol) SELECT IDENT_CURRENT('table')+1,'S',id, 1 FROM table2 return error Violation of PRIMARY KEY constraint 'PK__table__3213E83F2B947552'. Cannot insert duplicate key in object 'table'. The duplicate key value is (6). only 'id' i need get from table2 Jessica Gonz�lez (jess.rgm@gmail.com) writes: > thanks.. but > > SET IDENTITY_INSERT table ON; > INSERT INTO table(pk,activo,permiso,rol) > SELECT IDENT_CURRENT('table')+1,'S',id, 1 > ...

how to have a while inside a for inside a while :(
so, its like the inception movie, but i really need this, i know its easy but i cant figure it out i am working with FEM and have to track one particle, every element has a unique velocity so i need them to update when they cross from one element to another so its like this %%%%%%%%%%%%%%%%%%%%%%%%% dox=0; doy=5; while (dx<=2.8) || (dy>=4.8) for i=1:5 while dx<=(a*i) dx=dox+t*dhdx(141+i) % al pasar a i =2 el tiempo debe empezar de 0 dy=doy+t*dhdy(141+i) dxVector=[dxVector; dx]; dyVector=[dyVector; dy]; dox=dx; ...

shell redirect
Hi, Is it possible to redirect stdout, stderr of the current shell something like : exec xx > test.log 2> test.err Thanks in advance astalavista wrote: > Hi, > > Is it possible to redirect > stdout, stderr of the current shell > something like : > exec xx > test.log 2> test.err exec > test.log 2> test.err (Not sure how that would make sense in an interactive shell, though.) Janis > > Thanks in advance > > "Janis Papanagnou" <Janis_Papanagnou@hotmail.com> a �crit dans le message de news: fihv01$rv5$1@onli...

Unix shell
Hi all, We offer free shells with web hosting and a spam-filtered email account. - 50MB storage space (more available upon request) - Domain hosting available upon request - Access via SSH, SFTP, and POP3-ssl - Instant messaging clients for IRC, AIM, MSN, ICQ, Yahoo!, Gadu-Gadu, Jabber, and Lily - FastTrack (KaZaA), SoulSeek, and BitTorrent clients - Optional trainable server-side spam detection is also included. We also have a few vhosts for fans of IRC. Instant accounts available at: http://silenceisdefeat.org/ Anyway, I hope this is an acceptable place to let you guys know. If i...

For loop while loop
I need to evaluate a function from 0:200 then create an array of every 5th value in the 0:200 array using a for loop then using a while loop. I can't get the for loop to work at all because I cannot use >,< controllers, only an =. So I focused on the While loop: n=0:200;%creates 201 cell array from 0-200 x=n.^2+.25;%calculates x plotcol=(length(n)-1)/5;%=(201-1)/5=40 y=zeros(1,plotcol);%creates 1X40 vector col=1;%used for incrementing in while loop while col<=plotcol; y(1,col)=x(1,5*col); col=col+1; end Unfortunately the output starts at 16 when it should start at 0. It seems like it should work to me, but something is messed up. Any help would be appreciated. "mpl " <mpl@mathworks.com> writes: > I need to evaluate a function from 0:200 then create an > array of every 5th value in the 0:200 array using a for > loop then using a while loop. > > I can't get the for loop to work at all because I cannot > use >,< controllers, only an =. > > So I focused on the While loop: > > n=0:200;%creates 201 cell array from 0-200 > x=n.^2+.25;%calculates x > plotcol=(length(n)-1)/5;%=(201-1)/5=40 > y=zeros(1,plotcol);%creates 1X40 vector > col=1;%used for incrementing in while loop > while col<=plotcol; > y(1,col)=x(1,5*col); > col=col+1; > end > > Unfortunately the output starts at 16 when it should start > at 0. It seems like it should work to me, ...

loops in loops
In the attached vi, the one second loop runs at one second and can't be touched.&nbsp; In the ten second loop, the ten second clock is a stand in for a process that generates a finished signal. The problem is once the process is complete, to start it again, leave the one second loop running, and start an additional process that will take less time than 10 seconds. thanks internal loops.vi: http://forums.ni.com/attachments/ni/170/319512/1/internal loops.vi Hi exo, what do you try there? If you start your vi, the value from your stop button will be read and after that, both loops "one" second and "ten" second won�t notice the state change of the stop button. Can you please explain, what you try to do?? Mike Okay, let me try again. I need three loops. Two loops start at the same time one runs fast one runs slow. The slow one is probably independent to the problem. When the second loop is done, it needs to restart and start a third loop that takes less than the second. You have a very basic dataflow problems. Unfortunately, I don't understand your description. &nbsp; I would recommend starting with some basic LabVIEW tutorials. &nbsp; Here are some&nbsp;obvious mistakes: - Your loop cannot read changes in the stop button, because the terminal is outside the loop. - You reset "internal loop" to zero in parallel to the loops. You cannot guarantee that this will happen before the locals are read so you might have a race c...

while loop in a while loop
Hi All, I have the following situation: while(rs.next()) { //loop1 while(rs2.next()) { //loop 2 } } It seems like loop 2 is only beeing used once. Should I after loop2 put the cursor back to the beginning? if so, how do I do that? Thanks! -- Posted by news://news.nb.nu Steven wrote: > Hi All, > > I have the following situation: > > > while(rs.next()) { //loop1 > > while(rs2.next()) { > //loop 2 > } > > } > The architypal loop (for a List eg ArrayList of Blah objects) is: for(It...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of Banking, payment and messaging systems. Exp with Unix, shell Scripting, MQ Series, Oracle, Crystal Reports and WebSphere. Strong analytical skills. Ability to analyze a problem. own the problem and follow thru to resolution. Production support experience with critical systems. Good written and oral communication skills. Scope: Knowledge of Banking, payment and messaging systems. Experience with Unix, shell Scripting, MQ Series, Oracle, Crystal Reports and WebSphere. Strong analytical skills. Ability to analyze a problem. own the problem and follow thru to resolution. Production support experience with critical systems. Good written and oral communication skills. Please send your...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of Banking, payment and messaging systems. Exp with Unix, shell Scripting, MQ Series, Oracle, Crystal Reports and WebSphere. Strong analytical skills. Ability to analyze a problem. own the problem and follow thru to resolution. Production support experience with critical systems. Good written and oral communication skills. Scope: Knowledge of Banking, payment and messaging systems. Experience with Unix, shell Scripting, MQ Series, Oracle, Crystal Reports and WebSphere. Strong analytical skills. Ability to analyze a problem. own the problem and follow thru to resolution. Production support experience with critical systems. Good written and oral communication skills. Please send your...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

Web resources about - Fixing stdin inside a redirected loop... - comp.unix.shell

Category:Wikipedia soft redirected project pages - Wikipedia, the free encyclopedia
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization.

Agile Artisans: You'll be redirected in just a moment...
Agile Artisans: You'll be redirected in just a moment...

Logged-Out Users Cannot See Facebook Pages’ Content; Redirected To News Feed After Login
Web surfers who are not logged in to Facebook and try to access pages on the social network are landing on the news feed once they input their ...

Flickr: The Help Forum: [locked, redirected] flickr now censoring all moderate and restricted photos ...
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

Prank of the Day: Someone Bought Anti-Gay Group’s Expired Domain Name, Redirected It to Gay Porn
Anti-gay protesters were picketing outside the Carolina Rebellion rock festival at the Charlotte Motor Speedway earlier this month, so one of ...

Smartphones redirected to Candy Crush, porn sites automatically - Technology - Tech News and Latest New ...
IT IS truly a 21st century problem, but one with potentially very serious implications. It may have even happened to you.

Smartphones redirected to Candy Crush, porn sites automatically
IT IS truly a 21st century problem, but one with potentially very serious implications. It may have even happened to you.

Bill Shorten's leadership ballot under scrutiny after Sam Dastyari's office redirected papers
The integrity of the vote that installed Bill Shorten as federal Labor leader has been brought into question by an official ALP tribunal which ...

Attack on Dailymotion redirected visitors to exploits
Attackers injected malicious code into Dailymotion.com, a popular video sharing website, and redirected visitors to Web-based exploits that installed ...

$200m redirected from wages to childcare training
THE Abbott government will redirect about $200 million that was meant to go to lifting childcare wages to helping long day care services with ...

Resources last updated: 3/16/2016 4:16:12 PM