开发者

Ruby: Run script from bash script?

开发者 https://www.devze.com 2023-02-15 09:22 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消