代码之家  ›  专栏  ›  技术社区  ›  Andrew

在bash中使用重映射文件作为包含源

  •  1
  • Andrew  · 技术社区  · 14 年前

    我在一个共享的网络主机上,在那里我没有编辑全局bash配置文件的权限 /ect/bashrc . 不幸的是,全局文件中只有一行, mesg y ,它将终端置于TTY模式并使 scp 以及类似的命令不可用。我的本地 ~./bashrc 包括全局文件作为源,如下所示:

    # Source global definitions
    if [ -f /etc/bashrc ]; then
        . /etc/bashrc
    fi
    

    我当前的解决方法使用 grep 要将全局文件(无违规行)输出到本地文件并使用 那个 作为一个来源。

    # Source global definitions
    if [ -f /etc/bashrc ]; then
        grep -v mesg /etc/bashrc > ~/.bash_global
        . ~/.bash_global
    fi
    

    有没有办法在不创建实际文件的中间步骤的情况下包含这样一个重映射文件?像这样的?

    . grep -v mesg /etc/bashrc > ~/.bash_global
    
    4 回复  |  直到 14 年前
        1
  •  5
  •   ghostdog74    14 年前

    把猫丢了,没用

    source <(grep -v "mesg" /etc/bashrc)
    

    这个 <() 语法被调用 process substitution .

        2
  •  2
  •   Ignacio Vazquez-Abrams    14 年前
    . <(grep -v mesg /etc/bashrc)
    
        3
  •  1
  •   Drakosha    14 年前

    我建议打电话 mesg n :)

        4
  •  0
  •   Isak Savo    14 年前

    从记忆中,但是

    grep -v mesg /etc/bashrc | eval
    

    应该有办法

    因为我不确定eval是否会读stdin,你可能需要把它改写成

    eval `grep -v mesg /etc/bashrc`