Hey guys and gals,
I'm not sure if this is possible in one line (i.e., without writing a script), but I want to run an ls | grep
command and then for each result, pipe it to another command.
To be specific, I've got a directory full of images and I only want to view certain ones. I can filter the images I'm interested in with ls | grep -i <something>
, which will return a list of matching files. Then for each file, I want to view it by passing it in to eog
.
I've tried simply passing the results in to eog
like so:
eog $(ls | grep -i <something>)
This doesn't quite work as it will only open the first entry in the result list.
So, how can I execute eog FILENAME
for each entry in the result list without having to bundle this operation into a script?
Edit: As suggested in the answers, I can use a for
loop like so:
for i in 'ls | grep -i ...'; do eog $i; done
This works, but the loop waits to iterate until I close the currently opened eog
instance.
Ideally I'd like for n
instances of eog
to open all at once, where n
is the number of results returned from my ls | grep
command. Is this possible?
Thanks everybody!