'Why does behavior of `./example` and `sh example` different? (`zsh: text file busy: ./example`)
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 1:[1]
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.
Solution 2:[2]
There are different shell environments on the Linux, such as sh, bash, zsh and etc.
In some shells, there are differences in the execution of the bash script.
when you use ./example it execute the script in the current shell.
when you use with bash example or sh example it will run on the the specific shell you want.
also you can use shebang in the first line of you script.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Philippe |
| Solution 2 | rezshar |
