bash命令行输入限制 [英] Bash command line and input limit

查看:226
本文介绍了bash命令行输入限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有输入多久可以是某种在bash(或其他shell)规定字符的限制?如果是这样,那是什么字符限制?

Is there some sort of character limit imposed in bash (or other shells) for how long an input can be? If so, what is that character limit?

即。是否有可能写在bash命令太长的命令行执行?
如果没有必需的限制,有没有建议限制?

I.e. Is it possible to write a command in bash that is too long for the command line to execute? If there is not a required limit, is there a suggested limit?

推荐答案

有一个命令行的长度的限制不是由外壳所施加的,而是由操作系统。通常,此限制是在几百千字节的范围内。 POSIX表示此限制 ARG_MAX 和POSIX一致性系统,你可以用它查询

The limit for the length of a command line is not imposed by the shell, but by the operating system. This limit is usually in the range of hundred kilobytes. POSIX denotes this limit ARG_MAX and on POSIX conformant systems you can query it with

$ getconf ARG_MAX    # Get argument limit in bytes

例如。在Cygwin这是32000,并在不同的Linux发行版我用的是从131072到2621440的任何地方。

E.g. on Cygwin this is 32000, and on the different Linux distros I use it is anywhere from 131072 to 2621440.

如果你需要处理的文件超过此限制的列表,你可能想看看的xargs 工具,这与参数的子集,不反复调用程序超过 ARG_MAX

If you need to process a list of files exceeding this limit, you might want to look at the xargs utility, which calls a program repeatedly with a subset of arguments not exceeding ARG_MAX.

要回答你的具体问题,是的,这是可能的尝试与过长的参数列表运行命令。外壳将伴随着参数列表太长。

To answer your specific question, yes, it is possible to attempt to run a command with too long an argument list. The shell will error with a message along "argument list too long".

注意的输入的一个程序(如读取标准输入或任何其他文件描述符)是的的限制(仅受可用程序资源)。所以,如果你的shell脚本读取一个字符串到一个变量,你没有被 ARG_MAX 限制。

Note that the input to a program (as read on stdin or any other file descriptor) is not limited (only by available program resources). So if your shell script reads a string into a variable, you are not restricted by ARG_MAX.

这篇关于bash命令行输入限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆