Ruby: Run a script from a bash script?

I am trying to call a Ruby script from a bash script, but no luck.

#!/bin/bash ruby -v 

works just fine, so I know this is not Ruby, but

 #!/bin/bash ruby bash_test.rb 

no. Here's the interesting part:

 john@starfire :~/Desktop$ bash ubuntu_cmds.sh (LoadError)h file or directory -- bash_test.rb john@starfire :~/Desktop$ ls *.rb bash_test.rb 

Both files are sitting on my desktop.

 ruby bash_test.rb 

works great.

I'm new to bash scripts, so I'm sure I'm just making a stupid mistake.

I am running Ubuntu 10.10 with Ruby 1.8.7. Thanks in advance for any help or advice.

EDIT: Removed .sh and .rb and started, and make sure chmod +x .sh, and this worked on the first try. I have no idea why. Thanks for the help, however.

+4
source share
3 answers

Do you have a carriage return in a bash script after the file name?


edited

Double checking how a file name is passed to a ruby ​​in a bash script.

The error output should be as follows if the file was not found

  ruby: No such file or directory - bash_test.rb (LoadError)

From what you show as an error, it seems that there is a carriage return that ruby ​​assumes as part of the file name, so you get the following error output.

  (LoadError) h file or directory - bash_test.rb
+3
source

to try

 #!/bin/bash ruby ~/Desktop/bash_test.rb 
+3
source

You may need to run ruby ./bash_test.rb , as sometimes . not in your $PATH .

+3
source

Source: https://habr.com/ru/post/1342862/


All Articles