Write the line starting with #!
On the first line of the file as shown below.
hoge.rb
#!/usr/bin/env ruby
(Program contents)
#!
Is a shebang, a command written below it that will re-execute itself.
By using / usr / bin / env
, you don't have to write the environment-dependent PATH that appears in which ruby
. / usr / bin / env
is also environment-dependent, but it is almost common, and if you can execute env with this PATH even if it is not included by default, it will be a problem after that I think it's okay because it doesn't exist.
After that
$ chmod +x hoge.rb
If you give execute permission,
$ ./hoge.rb
Can be executed like.
In other languages, you can replace the ruby
part with perl
, python
, etc.
hoge.py
#!/usr/bin/env python
Used to specify the character code,
# coding: utf-8
Etc. are brought to the second line, so it's OK.
http://x68000.q-e-d.net/~68user/unix/pickup?%A5%B7%A5%A7%A5%D0%A5%F3%A5%B0
Recommended Posts