Using #! comment in ruby ​​works in Ubuntu

I am new to programming and try to follow an example that uses #! comment in ruby.

I constantly get the message: bash: matz.rb: command not found

I am using this comment: #! / Usr / bin / env ruby

I tried this with and without a space after! as well as with and without env.

when i use $ which ruby

ruby is located in: / usr / bin / ruby

I also went into the operating system and changed the permissions on the matz.rb file to rwx for all inactivity users. Am I doing something wrong or misconfigured my system?

+5
source share
7 answers

/usr/bin/env . bash matz.rb . matz.rb, "./matz.rb". "." , - bash (, Windows).

env (/usr/bin/env) - PATH - ruby, . shebang . script , , , , "#!/usr/bin/env ruby", , , "".

+10

, matz.rb,

$ ./matz.rb

$ matz.rb

, :

$ ls -la m*
-rwxr-xr-x  1 gareth  gareth  32  8 Jan 08:46 matz.rb
$ cat matz.rb
#!/usr/bin/env ruby
puts "Matz"
$ matz.rb
-bash: matz.rb: command not found
$ ./matz.rb
Matz
+9

Windows? \r\n, bash. Vim :

vi matz.rb
:set ff=unix
:wq

"ff =" dos, . , dos2unix :

apt-get install sysutils
dos2unix matz.rb
+3

, Unix/Linux matz.rb . , . /matz.rb. "./" , , /usr/bin .

+2

, ,

chmod +x matz.rb

,

./matz.rb

.rb , , ruby ​​/rails, . script/generate, script/console ..

+1

"shebang" :

#!/usr/bin/ruby
#!/usr/bin/env ruby

script ( ) $PATH.

echo $PATH

script , , :

export PATH=$PATH:/home/user/bin

:

./matz.rb
/home/user/bin/matz.rb

Ruby, script , . , ​​ Ruby (, , Ruby Enterprise Edition, REE):

/usr/bin/ruby matz.rb
/opt/ree/bin/ruby matz.rb
+1

ShaBang , ruby?

#! /usr/bin/ruby

script

./matz.rb

Unix/Linux . /usr/bin/ruby, usr...

/ , .

/ .

ShaBang , "/usr/bin/ruby" . , , script , script . /matz.rb, bash , /usr/bin/matz.rb, .

0

All Articles