【问题标题】:bash --version. Where this info are stored?重击--版本。这些信息存储在哪里?
【发布时间】:2018-10-02 15:37:39
【问题描述】:

关于命令的信息存储在哪个文件中 bash --version ? 我尝试过一些目录,例如 /bin 或 /var、/etc,但没有结果...

Linux 和 MAC OS x 都需要。谢谢!

【问题讨论】:

  • 可能硬编码到可执行文件中。为什么不呢?
  • 出于好奇,您究竟在这些目录中尝试了什么?
  • 我正在寻找一些与 /bin/bash 可执行文件相关的变量...我几乎是新手 :D
  • @Alex_DeLarge 您可能应该查看~/.bashrc

标签: bash macos environment-variables


【解决方案1】:

您有任何理由相信它没有硬编码在bash-executable 本身中吗?

要找出使用了哪个bash,请运行

which bash

对我来说,它给了/bin/bash。现在,要查看可执行文件中是否有任何类似字符串的字节序列,其中包含子字符串"version",运行

strings /bin/bash | grep version

在这台机器上,它给出:

shell_version_string
build_version
sccs_version
rl_library_version
rl_do_lowercase_version
show_shell_version
rl_readline_version
dist_version
GNU bash, version %s-(%s)
GNU bash, version %s (%s)
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
@(#)Bash version 4.3.48(1) release GNU
display-shell-version
      -l    do not print tilde-prefixed versions of directories relative
    HOSTTYPE    The type of CPU this version of Bash is running under.
    OSTYPE  The version of Unix this version of Bash is running on.
    version, type `enable -n test'.
do-lowercase-version
.gnu.version
.gnu.version_r

因此,"Bash version 4.3.48" 在可执行文件中被硬编码为普通字符串。

【讨论】:

  • 清楚,谢谢。如果我想编辑一行怎么办?例如,在命令 bash --version 我得到 GNU bash,版本 4.4.12(1)-release (x86_64-pc-linux-gnu) 版权所有 (C) 2016 Free Software Foundation, Inc.,我想打印世界“ copyleft”而不是“copyright”
  • 你为什么关心措辞?如果这很重要,我很确定维护人员会在源代码中进行更改。您可以随时编辑源代码并自己重新编译。
  • @Alex_DeLarge 在可执行文件本身中?我想你可以为此使用一些十六进制编辑器,或者use hexdump in combination with sed。我不是律师,我不确定编辑别人的版权声明是否是个好主意。你为什么要这样做?
  • @Alex_DeLarge。您是否打算将上述可执行文件分发给其他人?
  • @Alex_DeLarge,你需要小心不要改变偏移量——你可以修改字符串,但前提是你保持它们相同的长度,或者有时如果你让它们更短,并添加 NUL 作为填充。否则,您可以拆卸、修改和重新组装......这当然也很有教育意义。
【解决方案2】:
strings $(which bash) | grep "Bash version"

输出(例如):

@(#)Bash 版本 4.3.48(1) 发布 GNU

【讨论】:

  • 字符串是否只提取二进制文件中看起来是有效 Unicode 的部分?
  • @MadPhysicist:GNU 字符串打印至少 4 个字符长且后跟不可打印字符的可打印字符序列。选项 --encoding=encoding 可能有助于 Unicode UTF-16/UCS-2 编码。
  • 感谢您让我变得懒惰 :) 我以前从未见过这个程序,但懒得搜索。
  • 我必须在安卓上谷歌它。不知道我会从那个特定的单词组合中得到什么:)
猜你喜欢
  • 2013-10-04
  • 1970-01-01
  • 1970-01-01
  • 2014-11-14
  • 2011-10-26
  • 2012-10-05
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多