1

The behavior of dash (and also bash) looks non-intuitive in this case.

It seems that new_file is created before ls is executed. Is it specified in POSIX?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
gadm
  • 11
  • 2
  • 1
    If it's non-intuitive, it's because your intuition on pipes is wrong. `ls` is not executed before `cat >newfile`: the two are executed at the same time. Whether `new_file` is created before or after `ls` reaches the point where it would list it is a race. It's a race that `>new_file` will usually win, because creating a file takes less long than reading an executable and starting to execute it. But if you run it a large number of times, I expect you'll sometimes see `ls` win. – Gilles 'SO- stop being evil' Jun 11 '20 at 19:28

0 Answers0