I made a bash file "my_sh.sh". by default it has no x permission:
-rw-rw-r-- 1 amin amin 37 Mar 12 00:45 my_sh.sh
But I could run it without any problem or warning! Why?
amin@ubuntu:~/newDIR$ bash my_sh.sh
I made a bash file "my_sh.sh". by default it has no x permission:
-rw-rw-r-- 1 amin amin 37 Mar 12 00:45 my_sh.sh
But I could run it without any problem or warning! Why?
amin@ubuntu:~/newDIR$ bash my_sh.sh
There is a difference in
./my_sh.sh
andbash my_sh.sh
./my_sh.sh
tells the kernel that it's a script which then looks at the first line (the shebang#!
) and uses said interpreter (?) to run the script, it needs have executable permissions for the kernel to do this. Edit: This will start another process as we are starting a new instancebash my_sh.sh
is asking bash to run the script and doesn't care so much of the first line. So (correct me if I am wrong) it just needs read permissions for bash to run itNote that there are plenty of other scripts we can write just like
.sh
scripts, python for example:python my_py.py
is different from./my_py.py
(<= assuming you have the proper shebang)As was stated in the comments, when writing script files, leaving out the shebang line, the script will use the current shell environment which if the script uses a different shell ie the script uses
ksh
but your shell environment isbash
(thank you Sergiy Kolodyazhnyy for the example :) ) this can lead to errors.