[CentOS] Re: ls and rm: "argument list too long"

Robert Nichols rnicholsNOSPAM at comcast.net
Sat Oct 18 12:43:53 UTC 2008


Les Mikesell wrote:
> Robert Nichols wrote:
>>
>>> These shouldn't make any difference.  The limit is on the size of the 
>>> expanded shell command line.
>>
>> Really?
>>
>> $ M=0; N=0; for W in `find /usr -xdev 2>/dev/null`; do M=$(($M+1)); 
>> N=$(($N+${#W}+1)); done; echo $M $N
>> 156304 7677373
>>
>> vs.
>>
>> $ /bin/echo `find /usr -xdev 2>/dev/null`
>> bash: /bin/echo: Argument list too long
>>
>> For the first case, the shell never tries to pass the list as command 
>> arguments.
>> It builds the list internally, limited only by memory size, and 
>> processes the
>> words one by one.
> 
> Is that peculiar to bash?  I thought the `command` construct was 
> expanded by shells into the command line before being evaluated.

I can't answer for how any particular shell allocates its internal memory,
but yes, the shell does read the entire output from `command` before
evaluating it.  If this data is simply being used internally it never
gets passed to the kernel as an argument to exec() and thus can never
result in errno==E2BIG (7, "Argument list too long").

-- 
Bob Nichols     "NOSPAM" is really part of my email address.
                 Do NOT delete it.



More information about the CentOS mailing list