bash 是否可以增加 ksh 变量接受的最大字符数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14387344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:16:57  来源:igfitidea点击:

Is it possible to increase the maximum number of characters that ksh variable accepts?

linuxbashunixksh

提问by javapadawan

This is a follow up question to

这是一个后续问题

What is the maximum number of characters that the ksh variable accepts?

ksh 变量接受的最大字符数是多少?

I checked my environment and it's allowing only

我检查了我的环境,它只允许

#include <sys/limits.h>
$ cpp <<  HERE | tail -1
> #include <limits.h>
> ARG_MAX
> HERE
1048576

Is there a way to increase this? Or any alternatives for

有没有办法增加这个?或任何替代品

 while read line;
   do
      #parse logic
   done < $filename

To handle really long lines? Based from the records I'm parsing it will not stop at 2M character lines.

处理很长的线路?根据我正在解析的记录,它不会在 2M 字符行处停止。

Environment Details :

环境详情:

 AIX $ KSH Version M-11/16/88f 

采纳答案by Basile Starynkevitch

You could compile a Linux 3.7.x kernel, and edit its include/uapi/linux/limits.hfile to increase the ARG_MAXargument (to some bigger power of two, e.g. 2097152). But you should rather have a lot of RAM (e.g. 8GBytes) if you want to increase it more.

您可以编译 Linux 3.7.x 内核,并编辑其include/uapi/linux/limits.h文件以增加ARG_MAX参数(到更大的 2 次方,例如 2097152)。但是,如果您想增加更多内存,您应该拥有大量 RAM(例如 8GBytes)。

The actual limit is related to execve(2). That man page has a paragraph on it.

实际限制与execve(2) 相关。该手册页上有一段。

But you could probably avoid having huge shell variables (in the Unix environment). Did you consider using some other tool (awk, python, perl....) to read your file? Their variable environment is not the shell environment transmitted to forked programs, so they can have variables with very long values. Maybe kshhas some builtin (unexport) to avoid exporting some variable into the Unix environment.

但是您可能可以避免使用巨大的 shell 变量(在 Unix 环境中)。您是否考虑过使用其他工具 ( awk, python, perl....) 来读取您的文件?它们的变量环境不是传递给分叉程序的 shell 环境,因此它们可以具有非常长的值的变量。也许ksh有一些内置 ( unexport) 以避免将某些变量导出到 Unix 环境中。