I came across some bash (v5.1.16) behavior today that surprised me:
~ > export TEST=`python -c "print('a'*131067)"` # This works.
~ > export TEST=`python -c "print('a'*131067)"` # This does not.
-bash: /usr/bin/python: Argument list too long
~ > export TEST=`python -c "print('a'*131067)"` # This works.
~ > export TEST=`python -c "print('a'*131067)"` # This does not.
-bash: /usr/bin/python: Argument list too long
Note how the first line succeeds, and the second does not. The behavior repeats reliably: setting TEST
works, then it doesn’t, then it does, then it doesn’t...
This is on Gentoo Linux 5.18.5. Interestingly, 131066
works always; on Mac it’s 259832
that works, and one more fails.
Related perhaps: Difference between single and double quotes in Bash
What’s going on here?
Addendum: Thanks @dave-thompson-085 for your answer below.
With some more digging I found these two related discussions: What is the maximum size of a Linux environment variable value? and How to get around the Linux "Too Many Arguments" limit. Also, reading the docs for execve()
helps, particulalry the section Limits on size of arguments and environment.