You have multiple options.
Read from stdin
One option is to read from stdin. You can for example do in search.sh
#!/usr/bin/env ruby
input = $stdin.read
puts "here's the input i got:"
puts input
Suppose we have a file foo.txt which looks like this
foo
bar
baz
then you can use it with a unix pipe
~$ ./search.sh < foo.txt
here's the input i got:
foo
bar
baz
which is equivalent to
~$ cat foo.txt | ./search.sh
here's the input i got:
foo
bar
baz
although this is useless use of cat and just meant to serve demonstration purposes. You can not only pipe files but also output from other commands
~$ echo "hello, world!" | ./search.sh
here's the input i got:
hello, world!
if you want to redirect the output to another file, do
~$ ./search.sh < foo.txt > bar.txt
~$ cat bar.txt
here's the input i got:
foo
bar
baz
Read file from Ruby
Another way is to just pass the file name as argument and read the file directly from Ruby:
#!/usr/bin/env ruby
file = ARGV.first
input = File.read(file)
puts "here's the input i got:"
puts input
Usage:
~$ ./search.sh foo.txt
here's the input i got:
asfdg
sdf
sda
f
sdfg
fsd
and again to redirect the output use >
~$ ./search.sh foo.txt > bar.txt