【问题标题】:Why escape the first character of eval in .profile script? [duplicate]为什么在 .profile 脚本中转义 eval 的第一个字符? [复制]
【发布时间】:2019-06-20 00:10:54
【问题描述】:

我在 Mac 上安装了 anaconda,我注意到它在我的 .profile 中附加了以下内容:

# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

我对“\eval”和“\export”行的转义感到有些困惑。这样做的目的是什么?我怀疑它与便携性有关,但我以前从未见过。

有人能解释一下它的用途吗?

【问题讨论】:

  • @Spencer:你是对的,我的问题确实是重复的。不幸的是,当您有问题时,搜索的内容并不总是很明显......

标签: bash shell anaconda


【解决方案1】:

它被引用以防它被别名为其他命令。请参见以下示例:

[STEP 101] $ alias foo='echo hello world'
[STEP 102] $ foo
hello world
[STEP 103] $ \foo
bash: foo: command not found
[STEP 104] $

根据 bash 手册:

检查每个简单命令的第一个单词,如果未引用,看它是否有别名。如果是这样,则该词将替换为别名的文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2015-12-27
    • 2011-01-11
    • 1970-01-01
    • 2011-05-14
    • 2018-01-11
    • 1970-01-01
    相关资源
    最近更新 更多