Reputation: 73
I have a directory of input files, each of which I am running cat on and piping to STDIN of a ruby program file, like so:
cat Laser-Maze-with-Mirrors_testcases/input005.txt | ruby laser-maze.rb
I have a feeling this is simple, but how do I pipe the cat of these files in one at a time? Right now I'm typing each one manually, which seems like a really dumb thing to do.
Upvotes: 0
Views: 100
Reputation: 19770
You can loop over the files. Note that redirection is probably a bit more direct than cat
in this case, and that you should always quote the arguments in a case like this in case there happen to be spaces in the files.
for f in Laser-Maze-with-Mirrors_testcases/*.txt; do
ruby laser-maze.rb < "$f"
done
Upvotes: 2
Reputation: 8326
Something as simple as
for file in /mypath/*
do
cat $file | ruby laser-maze.rb
done
should work in a shell script
Upvotes: 1