1

This question already has an answer here:

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.

marked as duplicate by filbranden, Rui F Ribeiro linux Nov 23 '18 at 4:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Try type echo – Scott Nov 23 '18 at 3:50
  • @Scott type: Command not found. – lionel319 Nov 23 '18 at 3:51
  • 1
    Please edit your question to say what shell you are using. – Scott Nov 23 '18 at 3:53
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.