简体   繁体   中英

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.

try

#!/bin/bash
ruby ~/Desktop/bash_test.rb

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

You may have to do ruby ./bash_test.rb , as sometimes . isn't in your $PATH .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM