Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: Run script from bash script?

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

#!/bin/bash
ruby -v

works just fine, so I know that it's not Ruby, but

#!/bin/bash
ruby bash_test.rb

does not. Here's the fun 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 just fine, too.

I'm new to bash scripting, so I'm pretty sure that I'm just making a stupid error.

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

EDIT: Deleted the .sh and the .rb and started over, and made sure to chmod +x the .sh, and it worked on the first try. I have no idea why. Thanks for the help, though.

like image 563
eckza Avatar asked Mar 08 '11 18:03

eckza


2 Answers

try

#!/bin/bash
ruby ~/Desktop/bash_test.rb
like image 160
rubyprince Avatar answered Oct 25 '22 17:10

rubyprince


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


EDITED

Double check how the filename is being passed to ruby in the bash script.

Error output should be as below if the file wasn't found

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

From what you are displaying as an error it appears that there is a carriage return that is being assumed by ruby as part of the filename so you are getting the following error output.

 (LoadError)h file or directory -- bash_test.rb
like image 39
Chaim Geretz Avatar answered Oct 25 '22 19:10

Chaim Geretz