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
?
CodePudding user response:
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.
CodePudding user response:
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.