Thursday, April 7, 2022

[SOLVED] Why does behavior of `./example` and `sh example` different? (`zsh: text file busy: ./example`)

Issue

I tried this:

$ exec 3> example
$ lsof example 
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
zsh     10711 lane    3w   REG  253,0        0 9231034 example

It will show text file busy if I do this:

$ ./example  
zsh: text file busy: ./example

But if I execute it using sh, it will be OK(no error):

$ sh example 
$

What is the difference between ./example and sh example?


Solution

When you do

$ ./example

you are trying to execute "example" which is being written to. This is not allowed.

When you do

$ sh example

sh is reading "example", then execute what is read. This is fine.



Answered By - Philippe
Answer Checked By - Katrina (WPSolving Volunteer)