1

I have a ruby bin I'd like to pass information to in this fashion:

some_text | ./bin/my_ruby_bin

where some_text will be accessible by ARGV

is this possible with ruby + shell or am I taking the wrong approach here?

lfender6445
  • 29,844
  • 11
  • 111
  • 95

1 Answers1

1

Here is simple solution that works for my cause, but it appears there are many ways to do this:

# ./bin/my_ruby_bin
#!/usr/bin/env ruby -n
puts "hello: #{$_}"

notice the -n flag

from command line:

echo 'world' | ./bin/my_ruby_bin
# => hello world

More on ruby -n

ruby -h
-n assume 'while gets(); ... end' loop around your script
lfender6445
  • 29,844
  • 11
  • 111
  • 95