【问题标题】:Trying to understand Bash file setups/structure试图了解 Bash 文件设置/结构
【发布时间】:2019-10-16 14:55:53
【问题描述】:

这是对之前提出的问题的扩展:What are some common HDFS commands that can be mapped in the bash files?

我注意到我最初提供的 .bashrc 和 .bash_profile 与您提供的略有不同。这是可以的还是某种不同的模式?

我开始时复制过来的文件如下:

.bashrc
.bash_profile

.bashrc

source /etc/bashrc 

...and a lot of other folder mappings

.bash_profile

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

我按照您的建议创建了 .bash-aliases 文件。

.bash_aliases

alias h="hdfs dfs"

我修改了.bashrc文件如下

.bashrc - 修改

source /etc/bashrc 

...and a lot of other folder mappings

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

【问题讨论】:

    标签: bash hadoop hdfs command-line-interface putty


    【解决方案1】:

    .bashrc 代码将在每个新 shell 启动之前执行。里面的代码无关紧要,只要它是有效的 bash。

    其他文件(bash_aliases)只是在这里分隔不同文件中的命令。

    这篇文章解释的很好:https://ss64.com/bash/syntax-bashrc.html

    所以要回答你的问题,它根本不会引起问题。重要的是它的完成方式让您满意。

    【讨论】:

    • 那么,我可以通过将.bashrc 中的所有代码移动到.bash_profiles 然后压缩.bashrc 以引用.bash_profiles 和.bash_aliases 来合理化事情吗?
    • @JWeezy bash_profile 有点不同,它在 bash 用作交互式登录 shell 时使用(例如当你 ssh 时),所以我不建议这样做,除非你希望您的交互式登录外壳具有与“普通”外壳相同的行为。但是,是的,您可以将代码从 bashrc 移动到随机文件中,然后从 bashrc 获取该文件
    • 啊,有道理。我不知道.bash_profile 专门用于交互模式。感谢您的帮助。
    猜你喜欢
    • 2015-12-25
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多