Is the error message translated? I would expect something more like "argument list too long".
First thing (although it won't help you with this exact problem - just a general tip) - you don't need to do this:
Code:
for rpt in `ls myfiles*.txt`
This will often work, but it's not the best way. It works by the backtick syntax running the command "ls myfiles*.txt", and taking the result of that an substituting it as the for loop list. The problem is that if you have a file with a space in the name, it will be split when the output of ls is read, and you will probably get two or more iterations of the loop on non-existing, or (worse) incorrect files.
The good news is, the shell will expand glob patterns for you, so just do this instead:
Code:
for rpt in myfiles*.txt
OK, back to the real problem. The shell has a limit to the number (and total length) of items in an argument list. This is most often encountered when you expend a glob pattern which matches a very large number of files. There are a few solutions. The simplest one when you have multiple commands to use with arguments (as you do) is to use find to identify the files, and then read the output of find into a while loop:
Code:
find . -name "myfiles*.txt" -maxdepth 1 -type f |while read rpt
do
instruction 1 $rpt
instruction 2 $rpt
...
instruction n $rpt
done
The disadvantage here is that the code block of the while loop is executed in a sub-shell. This means that you cannot modify the value variables in your main script inside the loop, and then read the modified values once the while loop is complete.
[/CODE]#!/bin/bash
counter=0
seq 1 5 | while read n; do
let counter+=1
echo "random number $counter is $RANDOM"
done
echo "after loop, value of counter is: $counter"[/CODE]
I hope that helps.