linux - Why i can excute a newly created file which is not executable? -


in ubuntu, default umask on ubuntu 022 means newly created files readable everyone, writable owner, nobody can excute it. in case, create new file :

touch test.rb  # content is: puts "hello world" ls -l demo.rb  # -rw-r--r-- 

then excute test.rb :

ruby test.rb  # output: "hello world" 

since owner of file not have "x" permission , why can run file ? or have missed knowledge ?

you not executing file binary. executing ruby binary argument test.rb , interprets ruby script. therefore, ruby binary needs execution privilage , not script itself.

you can check privileges of binary running stat (which ruby).

on other hand if place

#!/usr/bin/ruby 

on top of script , make executable chmod a+x test.rb make linux run it. binfmt module of kernel check search #! (called shebang) in file , run interpreter you.

you can find shebang in lot of shell scripts. nowadays common put #!/usr/bin/env ruby or #!/usr/bin/env python in order use interpreter binary in other location available on path variable /usr/local/bin/ruby. again env binary program. run argument program. kernel pass script parameter result in command /usr/bin/env ruby test.rb.


Comments