Re: Bash does not read up the whole script which it is currently executing

2009-08-06 Thread Ivan Zahariev


On Aug 5, 2:05 pm, Marc Herbert marc.herbert+n...@gmail.com wrote:
 I am not sure I get this... first of all, the script itself is usually
 not read from stdin (but from fd 255 in bash).

 Now considering the seldom cases where the script is actually read from
 stdin, are you saying that: it is a wanted feature that subprocesses can
 concurrently slurp and steal the code executed by their parent? Wow,
 that sounds really weird and not something I would wish, but rather a
 design limitation that I should constantly worry about.

 Regards,

 Marc

Same here, as Marc said.

I think that usually we are reading the script from a file and this is 
the use-case we must focus on. Currently, we have the problem I 
described when executing a script from a file and I think this must be 
fixed/changed.


--Ivan


John Reiser wrote:

On 08/04/2009 12:48 AM, fam...@icdsoft.com wrote:
It is an intended design feature that the shell reads only as much as 
necessary
to proceed at the moment.  This is required so that subprocesses can 
share the same
stdin as the shell.  Bytes for input to the shell alternate with bytes 
for input
to each subprocess that does not have redirection (or closure) specified 
for its stdin.


To avoid this feature, then use the -c parameter to specify the entire 
shell input

as a string on the command line:
bash -c $( filename)
Or, make a temporary unique copy of the file, then invoke the shell on 
the copy.







Re: Bash does not read up the whole script which it is currently executing

2009-08-06 Thread Marc Herbert
Ivan Zahariev a écrit :

 Same here, as Marc said.
 
 I think that usually we are reading the script from a file and this is 
 the use-case we must focus on. Currently, we have the problem I 
 described when executing a script from a file and I think this must be 
 fixed/changed.

Hey, wait. I am not saying that this must be changed. I can imagine
there are good reasons for the current behaviour (like for instance
performance or conformance).

Just not the reason put by John.





Re: Bash does not read up the whole script which it is currently executing

2009-08-05 Thread Marc Herbert
John Reiser a écrit :
 On 08/04/2009 12:48 AM, fam...@icdsoft.com wrote:
  First I would like to say that I'm not sure if this is a bug or a 
 feature of Bash.
  If it is a feature, please let me know how to turn it off; or better 
 make it disabled by default...
  
  The problem is that Bash does not read up the whole script which it is 
 currently executing.
  As a result of this, if we update the script file with a newer version 
 while it is running, this may lead to unpredicted results.
 
 It is an intended design feature that the shell reads only as much as 
 necessary
 to proceed at the moment.  This is required so that subprocesses can share 
 the same
 stdin as the shell.  Bytes for input to the shell alternate with bytes for 
 input
 to each subprocess that does not have redirection (or closure) specified for 
 its stdin.

I am not sure I get this... first of all, the script itself is usually
not read from stdin (but from fd 255 in bash).

Now considering the seldom cases where the script is actually read from
stdin, are you saying that: it is a wanted feature that subprocesses can
concurrently slurp and steal the code executed by their parent? Wow,
that sounds really weird and not something I would wish, but rather a
design limitation that I should constantly worry about.

Regards,

Marc








Re: Bash does not read up the whole script which it is currently executing

2009-08-04 Thread John Reiser

On 08/04/2009 12:48 AM, fam...@icdsoft.com wrote:

First I would like to say that I'm not sure if this is a bug or a 
feature of Bash.
If it is a feature, please let me know how to turn it off; or better 
make it disabled by default...

The problem is that Bash does not read up the whole script which it is 
currently executing.
As a result of this, if we update the script file with a newer version 
while it is running, this may lead to unpredicted results.


It is an intended design feature that the shell reads only as much as necessary
to proceed at the moment.  This is required so that subprocesses can share the 
same
stdin as the shell.  Bytes for input to the shell alternate with bytes for input
to each subprocess that does not have redirection (or closure) specified for 
its stdin.

To avoid this feature, then use the -c parameter to specify the entire shell 
input
as a string on the command line:
bash -c $( filename)
Or, make a temporary unique copy of the file, then invoke the shell on the copy.

--




Re: Bash does not read up the whole script which it is currently executing

2009-08-04 Thread Greg Wooledge
On Tue, Aug 04, 2009 at 08:23:16AM -0700, John Reiser wrote:
 On 08/04/2009 12:48 AM, fam...@icdsoft.com wrote:
  The problem is that Bash does not read up the whole script which it 
  is currently executing.
  As a result of this, if we update the script file with a newer 
  version while it is running, this may lead to unpredicted results.

 To avoid this feature, then use the -c parameter to specify the entire 
 shell input
 as a string on the command line:
   bash -c $( filename)
 Or, make a temporary unique copy of the file, then invoke the shell on the 
 copy.

Or upgrade your scripts like this:

  mv -f /path/to/script /path/to/script.old
  cp newscript /path/to/script

(Or remove-then-copy, or make /path/to/script a symlink to a
version-stamped copy, or any number of other ways that are not
vi /path/to/script.)