Issue
I am trying to set an environment variable the value of which happens to be too long. As soon as I am done with the export I am getting this error for all the commands.
-bash: /usr/bin/ls: Argument list too long
Is there a way I can still set this env variable or if I can increase the size of ARG_MAX
I am using 5.4.0-139-generic
kernel version and Ubuntu 20.04
Solution
This is a FAQ: https://stackoverflow.com/search?q=Argument+list+too+long. TL;DR: The problem is not the length of any individual env var. The problem is the total length of all env vars and CLI arguments passed to a program. The error is because the execve
syscall (used to run a program) is returning error E2BIG
(man execve
). Depending on the OS you may be able to increase the limit. But really, if you have an env var that is so large it is causing this problem you should be storing the data someplace other than an env var. Perhaps in a file whose name is the value of an env var.
Answered By - Kurtis Rader Answer Checked By - Willingham (WPSolving Volunteer)