【问题标题】:length of a variable in UNIX [duplicate]UNIX中变量的长度[重复]
【发布时间】:2014-10-30 03:24:26
【问题描述】:

如果有人可以请告诉我一个 UNIX 变量可以占用的总长度是多少。 我有一个名为 filelist 的变量,我想像这样保存内容:

filelist=path/name path/name path/name path/name path/name path/name 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称 路径/名称.....无穷大

【问题讨论】:

  • 哪个外壳?我假设 BASH?
  • 你最好使用一个文件来存储它。无论如何,你必须管理数据。我真的不知道,但我确信有更好的方法来做到这一点
  • 好的...我需要这个,因为我想稍后再做 scp $filelist id@remotohost:path

标签: linux unix


【解决方案1】:

有两个限制。第一个在外壳内。我猜bash 并没有限制很多变量,真正的限制是可用资源(如果malloc 失败)。

更重要的一个(与您的 scp $filelist id@remotohost:path 案例相关)是您使用该变量时,例如执行一些程序。然后execve(2) 被调用,它可能会因为整个程序参数占用太多内存而失败。阅读手册页的参数和环境大小限制部分:

参数大小和环境的限制

   Most UNIX implementations impose some limit on the total size of the
   command-line argument (argv) and environment (envp) strings that may
   be passed to a new program.  POSIX.1 allows an implementation to
   advertise this limit using the ARG_MAX constant (either defined in
   <limits.h> or available at run time using the call
   sysconf(_SC_ARG_MAX)).

实际上execve 的限制很重要(例如,默认情况下为 128Kbytes)。我经常在编辑一些内核头文件以提高该限制(例如提高到 1Mbyte)后编译自己的内核。

请注意,bash 中的 export-ed 变量会进入(未来派生进程的)环境,但会受到上述限制。

顺便说一句,您可以通过其他方式传输文件(rsyncgit 等...)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-05
    • 2017-08-09
    • 2016-10-19
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2020-06-21
    相关资源
    最近更新 更多