Why do I get "/bin/sh: Argument list too long" when passing quoted arguments?

Viewed 44235

How long can be a command line that can be passed to sh -c ''? (in bash and in bourne shell)

The limit is much lower than that from the OS (in case of modern Linux).

For example:

$ /bin/true $(seq 1 100000)
$ /bin/sh -c "/bin/true $(seq 1 100000)"
bash: /bin/sh: Argument list too long

And how could I circumvent this problem?

Update

I want to note that getconf can't help here (because that is not a system limit):

$ seq 1 100000 | wc -c
588895
$ getconf ARG_MAX
2097152

Update #2

Now I've understood what is the point here. That is not a shell limit, that is a system limit but for the length of each argument, not for the entire arglist.

$ /bin/true $(seq 1 100000)
$ /bin/true "$(seq 1 100000)"
bash: /bin/true: Argument list too long

Thank you, CodeGnome, for the explanation.

4 Answers
Related