Re: ls and rm: "argument list too long"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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.

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux