扩展模块化的.bash_配置文件?

扩展模块化的.bash_配置文件?,bash,Bash,我有两台笔记本电脑——一台用于工作,一台用于个人用品。我的.bash\u profile在每个上都有许多相同的函数和别名。然而,我的工作笔记本电脑的.bash\u profile上有一些东西在我的个人笔记本电脑上是不存在的 我想知道是否有一种方法可以制作一个“共享的”.bash\u配置文件或其他东西,并扩展它的功能,以便更容易在笔记本电脑之间共享我的bash内容 如果这很重要的话,我正在使用Mac电脑bash--版本==4.4.19解决方案1: 将常用内容放入共享的.bash\u配置文件中 so

我有两台笔记本电脑——一台用于工作,一台用于个人用品。我的
.bash\u profile
在每个上都有许多相同的函数和别名。然而,我的工作笔记本电脑的
.bash\u profile
上有一些东西在我的个人笔记本电脑上是不存在的

我想知道是否有一种方法可以制作一个“共享的”
.bash\u配置文件
或其他东西,并扩展它的功能,以便更容易在笔记本电脑之间共享我的bash内容

如果这很重要的话,我正在使用Mac电脑<代码>bash--版本==4.4.19解决方案1:

  • 将常用内容放入共享的
    .bash\u配置文件中
  • source~/.bashrc.local
    .bash\u profile
  • 每台笔记本电脑都有自己的
    .bashrc.local
  • 解决方案2:在两台笔记本电脑上使用一个
    .bash\u配置文件

    ... common stuff ...
    
    if [[ -f /a/file/only/on/work/laptop ]]; then
      ... now on work laptop ...
    else
      ... now on home laptop ...
    fi
    

    我有20多个Bash rc文件,因此我的实际解决方案有点复杂:

  • ~/.bashrc\u配置文件中只有一行:

    source ~/.bashrc
    
  • 所有系统共享相同的
    ~/.bashrc
    ,其中的逻辑如下:

    # Each system has its own `.bashrc.pre' which defines the
    # var `$RC_DIR' for top dir of all rc files (Bash, Vim, ...).
    #
    # I need to define my own `$RC_DIR' because my coworkers share
    # some servers (using the same accounts) at work.
    source ~/.bashrc.pre
    
    # `rcfiles' is system specific which lists rc files to be
    # loaded on that system. I maintain a `rcfiles.template'.
    for file in $(< $RC_DIR/bash/rcfiles); do
        source $file
    done
    
    # `.bashrc.post' is system specific
    source ~/.bashrc.post
    
    #每个系统都有自己的“.bashrc.pre”,它定义了
    #var`$RC_DIR'表示所有RC文件(Bash、Vim等)的顶部目录。
    #
    #我需要定义我自己的“$RC\u DIR”,因为我的同事共享
    #某些服务器(使用相同的帐户)正在工作。
    source~/.bashrc.pre
    #“rcfiles”是特定于系统的,它列出了要删除的rc文件
    #加载到该系统上。我维护一个“rcfiles.template”。
    对于$格式的文件(<$RC_DIR/bash/rcfiles);做
    源$文件
    完成
    #`.bashrc.post'是特定于系统的
    source~/.bashrc.post
    
  • 解决方案1:

  • 将常用内容放入共享的
    .bash\u配置文件中
  • source~/.bashrc.local
    .bash\u profile
  • 每台笔记本电脑都有自己的
    .bashrc.local
  • 解决方案2:在两台笔记本电脑上使用一个
    .bash\u配置文件

    ... common stuff ...
    
    if [[ -f /a/file/only/on/work/laptop ]]; then
      ... now on work laptop ...
    else
      ... now on home laptop ...
    fi
    

    我有20多个Bash rc文件,因此我的实际解决方案有点复杂:

  • ~/.bashrc\u配置文件中只有一行:

    source ~/.bashrc
    
  • 所有系统共享相同的
    ~/.bashrc
    ,其中的逻辑如下:

    # Each system has its own `.bashrc.pre' which defines the
    # var `$RC_DIR' for top dir of all rc files (Bash, Vim, ...).
    #
    # I need to define my own `$RC_DIR' because my coworkers share
    # some servers (using the same accounts) at work.
    source ~/.bashrc.pre
    
    # `rcfiles' is system specific which lists rc files to be
    # loaded on that system. I maintain a `rcfiles.template'.
    for file in $(< $RC_DIR/bash/rcfiles); do
        source $file
    done
    
    # `.bashrc.post' is system specific
    source ~/.bashrc.post
    
    #每个系统都有自己的“.bashrc.pre”,它定义了
    #var`$RC_DIR'表示所有RC文件(Bash、Vim等)的顶部目录。
    #
    #我需要定义我自己的“$RC\u DIR”,因为我的同事共享
    #某些服务器(使用相同的帐户)正在工作。
    source~/.bashrc.pre
    #“rcfiles”是特定于系统的,它列出了要删除的rc文件
    #加载到该系统上。我维护一个“rcfiles.template”。
    对于$格式的文件(<$RC_DIR/bash/rcfiles);做
    源$文件
    完成
    #`.bashrc.post'是特定于系统的
    source~/.bashrc.post
    

  • 当然,使用
    源代码
    命令将
    .bash\u配置文件
    分解为模块是可能的,而且这种情况并不少见

    从你的问题来看,你的
    .bash\u档案几乎是一样的,但唯一的区别是你的工作笔记本电脑上有特定于工作的东西。一种方法是将工作别名、函数、导出等移动到它们自己的文件中。我们称之为
    ~/.work\u profile

    然后在
    ~/.bash\u配置文件中添加以下内容。
    
    [-f~/.work\u profile]]和&source~/.work\u profile

    解释:
    [[-f~/.work\u profile]]
    测试常规文件
    ~/.work\u profile
    是否存在,如果存在,则返回true


    &&source~/.work_profile
    是一个逻辑和逻辑的文件。如果前面的命令返回true,那么它将运行此部分并为您的
    ~/.work\u profile

    确定使用
    source
    命令将
    .bash\u profile
    分解为模块是可能的,这并不罕见

    从你的问题来看,你的
    .bash\u档案几乎是一样的,但唯一的区别是你的工作笔记本电脑上有特定于工作的东西。一种方法是将工作别名、函数、导出等移动到它们自己的文件中。我们称之为
    ~/.work\u profile

    然后在
    ~/.bash\u配置文件中添加以下内容。
    
    [-f~/.work\u profile]]和&source~/.work\u profile

    解释:
    [[-f~/.work\u profile]]
    测试常规文件
    ~/.work\u profile
    是否存在,如果存在,则返回true


    &&source~/.work_profile
    是一个逻辑和逻辑的文件。如果上一个命令返回true,则它将运行此部分并生成您的
    ~/.work\u profile

    您可以在/etc中使用profile文件(如果您有root),或者使用
    源文件名
    包含其他(公共)文件


    您可能还想看看如何解释不同的可加载文件。

    如果您有根目录,您可以在/etc中使用配置文件,或者使用
    源文件名
    包含其他(通用)文件

    您可能还想了解一下如何解释不同的可加载文件