Incorrect use causes sh.exe to spoon infinitely

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Incorrect use causes sh.exe to spoon infinitely

leledumbo
Try running this buggy script:

for fin in `ls`; do
  # notice the missing backtick (`)
  fout=echo $fin | sed 's/\..*//'
done

And (quickly) open task manager, you'll see a lot (and growing) of sh.exe processes.
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect use causes sh.exe to spoon infinitely

Johannes Schindelin
Hi,

On Sun, 26 Jul 2009, leledumbo wrote:

>
> Try running this buggy script:
>
> for fin in `ls`; do
>   # notice the missing backtick (`)
>   fout=echo $fin | sed 's/\..*//'
> done
>
> And (quickly) open task manager, you'll see a lot (and growing) of sh.exe
> processes.

This is really a PEBCAK: "fout=echo $fin" is a valid invocation of $fin
with the environment variable "fout" set to the value "echo".

I am pretty certain that your "ls" returns a couple of shell scripts, and
they are executed.

Now, why the number is growing, I can only guess that the forks are the
issue (the sh.exe processes executing $fin not dying as quickly as the
sed calls return), but that is pretty normal, given what you asked shell
to do.

Ciao,
Dscho


------------------------------------------------------------------------------
_______________________________________________
Mingw-msys mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mingw-msys
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect use causes sh.exe to spoon infinitely

leledumbo
> I am pretty certain that your "ls" returns a couple of shell scripts, and
> they are executed.

No. I just simplify it, the real command is "ls *.java" which will only return java files. If sh then try to execute them, it should terminate with errors. In fact, the errors come out, but the process doesn't terminate. As additional information, the errors shown infinitely comes only from the first file.