Skip to main content
Post Undeleted by muru
deleted 292 characters in body
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 318

Both Python and RubyAt least one shell, fish, doesn't exhibit this behaviour for me(but then fish is unusual in other ways):

% printffor "%s\n"sh 'importin time'zsh 'time.sleep(3)'mksh >fish foo.py;dash python3bash foo.pytcsh; &do echo 'print("foo")''sleep >>5' > foo.py; fg                                                                                  $sh; $sh foo.$sh & sleep 1; echo 'echo $0' >> foo.$sh; fg; done
[1][2] 41037381
[1][2]  +- 41037381 running    python3$sh foo.py$sh
foo
 .zsh
% echo[2] 'sleep(3)'7385
[2] > foo.rb;- ruby7385 foo.rbrunning & echo 'puts("foo")' >>$sh foo.rb & fg                               $sh
[1] 4121foo.mksh
[2] 41227387
[2]  - 41227387 running    echo 'puts("foo")' >>$sh foo.rb$sh
%[2] foo
7390
[1]  + 4121[2] done - 7390 running    ruby$sh foo.rb
$sh
% python3 -Vfoo.dash
Python[2] 3.6.57393
%[2] ruby --version                                                                                                                                                                           7393 running    $sh foo.$sh
foo.bash
[2] 7415
[2]  - 7415 running    ruby$sh 2foo.5$sh
foo.1p57 (2018-03-29 revision 63029) [x86_64-linux]tcsh
 

I believe any interpreter capable(A previous version of readingthis answer had mistaken observations of Python and executing instructions as they come from a pipeline should behave the same wayRuby.)

Both Python and Ruby exhibit this behaviour for me:

% printf "%s\n" 'import time' 'time.sleep(3)' > foo.py; python3 foo.py & echo 'print("foo")' >> foo.py; fg                                                                                              
[1] 4103
[1]  + 4103 running    python3 foo.py
foo
 
% echo 'sleep(3)' > foo.rb; ruby foo.rb & echo 'puts("foo")' >> foo.rb & fg                               
[1] 4121
[2] 4122
[2]  - 4122 running    echo 'puts("foo")' >> foo.rb
% foo

[1]  + 4121 done       ruby foo.rb

% python3 -V
Python 3.6.5
% ruby --version                                                                                                                                                                                          ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

I believe any interpreter capable of reading and executing instructions as they come from a pipeline should behave the same way.

At least one shell, fish, doesn't exhibit this behaviour (but then fish is unusual in other ways):

% for sh in zsh mksh fish dash bash tcsh; do echo 'sleep 5' > foo.$sh; $sh foo.$sh & sleep 1; echo 'echo $0' >> foo.$sh; fg; done
[2] 7381
[2]  - 7381 running    $sh foo.$sh
foo.zsh
[2] 7385
[2]  - 7385 running    $sh foo.$sh
foo.mksh
[2] 7387
[2]  - 7387 running    $sh foo.$sh
[2] 7390
[2]  - 7390 running    $sh foo.$sh
foo.dash
[2] 7393
[2]  - 7393 running    $sh foo.$sh
foo.bash
[2] 7415
[2]  - 7415 running    $sh foo.$sh
foo.tcsh
 

(A previous version of this answer had mistaken observations of Python and Ruby.)

Post Deleted by muru
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 318

Both Python and Ruby exhibit this behaviour for me:

% printf "%s\n" 'import time' 'time.sleep(3)' > foo.py; python3 foo.py & echo 'print("foo")' >> foo.py; fg                                                                                              
[1] 4103
[1]  + 4103 running    python3 foo.py
foo

% echo 'sleep(3)' > foo.rb; ruby foo.rb & echo 'puts("foo")' >> foo.rb & fg                               
[1] 4121
[2] 4122
[2]  - 4122 running    echo 'puts("foo")' >> foo.rb
% foo

[1]  + 4121 done       ruby foo.rb

% python3 -V
Python 3.6.5
% ruby --version                                                                                                                                                                                          ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

I believe any interpreter capable of reading and executing instructions as they come from a pipeline should behave the same way.