1

I'm asking a question based on this link How to cause "Argument list too long" error?

From the thread, I'm seeing the equivalent error, if i'm running this:

>/bin/echo `perl -e 'print "x" x 1000000'`
/bin/echo: Argument list too long.

However, if I use echo instead of /bin/echo, it has no error, even if i exceeded way beyond the ARG_MAX

>echo `perl -e 'print "x" x 100000000'`
xxxxxxxxxxx...

Here's my environment

>which echo; getconf ARG_MAX
/bin/echo
2097152

I'm using tcsh.

lionel319
  • 111

1 Answers1

2

The difference is that echo is a built-in of your shell, while /bin/echo is an external executable.

The limitation on ARG_MAX is on the kernel syscall to execute an external binary (execve(2).)

When executing a built-in in your shell, no such limitations are imposed by the system, only limitations are from the shell itself, and most shells will simply not impose limits other than the memory available for them to store the arguments.

By the way, in this case, when you're executing the external /bin/echo, the actual limitation you're reaching is ARG_MAX_STRLEN, which is the maximum length of a single argument, and on Linux on Intel is hard-coded to 131,072 bytes. See this answer for more details. ARG_MAX is still the limit for all arguments (plus environment variables, etc.) But each single argument is limited by ARG_MAX_STRLEN. So even if you shorten your Perl expression to generate a shorter srring (like 132,000 characters), you should still reach this specific limit.

filbranden
  • 21,751
  • 4
  • 63
  • 86