0

I finished my short file for a homework assignment which uses IO.popen("command").readlines to grab the STDOUT of that command. However, I need to write a shell script to wrap my ruby file in. No problem, but somehow putting it in the shell script makes readlines hang.

ruby script.rb foo example > example.out

this works

script.sh foo example >example.out

this hangs on readlines. ruby script.rb is all that script.sh contains.

1 Answer 1

1

Looks like you forgot to pass your arguments to the ruby command. You may also be failing to specify an interpreter

script.sh

#!/bin/sh
ruby script.rb "$@"

Alternatively you could just add #!/usr/bin/ruby to the top of script.rb and make it executable (chmod +x script.rb). It's not a shell script. But it's generally the preferred way of executing a script in an interpretive language.

Once that's done you can run it with

./script.rb

Sign up to request clarification or add additional context in comments.

3 Comments

should be /usr/bin/ruby (without "e" in user)
Thanks for pointing that out. Sometimes the fingers are quicker than the brain.
alternatively, /usr/bin/env ruby

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.