当我打开终端时,是什么导致了所有这些“declare -x ...”行?

Dar*_*zer 16 linux command-line

当我在我的 Fedora 机器上打开一个终端(或 ssh 进入它)时,在提示之前我得到了一堆这样的行:

declare -x CVS_RSH="ssh"
declare -x DISPLAY="localhost:10.0"
declare -x G_BROKEN_FILENAMES="1"
declare -x HISTSIZE="1000"
…
Run Code Online (Sandbox Code Playgroud)

这是什么原因造成的?这可能是在我编辑了我的.bashrc.

更新(响应的回答):我 grep'ed ~/.bashrc~/.bash_profile/etc/bashrc为“声明”并没有发现任何东西。

我看了/etc/bashrc因为~/.bashrc包含以下内容:

if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
Run Code Online (Sandbox Code Playgroud)

除了上面的代码、“PATH=…”、“export…”和“alias…”之外,我在~/.bashrcor~/.bash_profile脚本中没有看到任何内容。

当我运行我的.bashrc脚本(使用“ bash ~/.bashrc”)或.bash_profile脚本时,我会看到“声明”列表,但没有错误消息。(如果我跑,我什么也看不见/etc/bashrc。)

~./bash_profile 很简单:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
Run Code Online (Sandbox Code Playgroud)

已解决:谢谢andrew.n,你的建议帮助我找到了它。事实证明,如果运行export(单独运行),所有这些“declare -x ...”行都会输出,并且我不小心在我的.bashrc.

and*_*w.n 8

env - HOME="$HOME" /bin/bash --login -xv 2>&1 | tee foo

以详细模式启动 bash。这将在读取初始化文件时打印每一行,并在执行时打印初始化文件的每一行,将输出复制到名为foo. 然后,您可以查看foo导致declare -x调用的原因。


小智 8

发现很多declare ...语句是在export没有参数的情况下在某处运行的结果。

我在我的.bashrc: 中发现了一个意外的换行符:

export
VARIABLE=value
Run Code Online (Sandbox Code Playgroud)

哪个应该是

export VARIABLE=value
Run Code Online (Sandbox Code Playgroud)