谁能解释这里发生了什么:
$ export a
$ a=`perl -e 'print "z"x1000000'`
$ a=`perl -e 'print "z"x1000000'`
bash: /usr/bin/perl: Argument list too long
$ a=`perl -e 'print "z"x1000000'`
$ a=`perl -e 'print "z"x1000000'`
bash: /usr/bin/perl: Argument list too long
Run Code Online (Sandbox Code Playgroud)
(perl one liner 制作一个包含 1000000 zs 的字符串)。为什么命令行对于每秒运行一次太长?
$ bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Run Code Online (Sandbox Code Playgroud)
编辑
失败的运行似乎取消了 $a 的设置。限制似乎是 131070。低于这个没有错误。
这是传递给execve的参数和环境变量的大小的限制。
ARG_MAX.请注意,传递给 execve 的字符串的最大长度和数量也有限制。它在 linux 源代码中进行了硬编码,并且无论允许的堆栈大小如何都适用。
您可以查看man 2 execve了解更多详细信息。
在第二次运行时,Perl 进程没有启动,因此命令替换`perl …`产生空输出并a设置为空值,从而将环境缩小到较小的大小。然后第三个命令成功并将环境设置为接近大小限制,依此类推。
为了更清楚,您可以尝试export a; a=$(yes | head -c128k),然后无法执行更多外部命令。