You have a few possible solutions:
Simply
$ ./script *g.log >output
... and hope that *g.log
doesn't expand to something that makes the command line too long. This is not very robust.
If your script doesn't depend on the number of files given to it, i.e., if output can just be appended to output
for each input file, then this is another solution:
$ find ./ -type f -name "*g.log" | xargs ./script >output
A third solution would be to move the loop into the script itself:
for f in *g.log; do
# old code using "$f" as file name
done
This does not have the problem with command line length restriction since it's in a script.
The invocation of the script would now be
$ ./script >output
*.log
may be expanded over theARG_MAX
limit causing anArgument list too long
error. That being said, your approach is the best solution unless OP really faces this issue. – Jedi Jun 21 '16 at 00:44grep
one-liner instead of a script. – Wildcard Jun 21 '16 at 03:03