使用grepped文件作为bash中包含的源 [英] Use a grepped file as an included source in bash

查看:173
本文介绍了使用grepped文件作为bash中包含的源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个虚拟主机提供商共享,我没有权限编辑在 /等/ .bashrc中全局bash的配置文件。不幸的是,在全球文件中的一行, MESG是,这使终端在TTY模式,使 SCP 和不可用类似的命令。我的地方〜/ .bashrc中包含全局文件作为来源,像这样:

 #源的全局定义
如果[-f的/ etc / bashrc中];然后
    。在/ etc / bashrc中
科幻

我目前的解决方法使用的grep 来输出全局文件,SANS犯罪行,为本地文件,并使用的的一个来源。

 #源的全局定义
如果[-f的/ etc / bashrc中];然后
    grep的-v ME​​SG在/ etc / .bashrc的> 〜/ .bash_global
    。 〜/ .bash_global
科幻

有没有办法做到有这样的grepped文件,而无需创建一个实际的文件的中间步骤?像这样的事情?

 。 grep的-v ME​​SG在/ etc / .bashrc的> 〜/ .bash_global


解决方案

失去的猫,它的无用

 来源≤(的grep -vMESG的/ etc / bashrc中)

≤()语法称为进程替换

I'm on a shared webhost where I don't have permission to edit the global bash configuration file at /ect/bashrc. Unfortunately there is one line in the global file, mesg y, which puts the terminal in tty mode and makes scp and similar commands unavailable. My local ~./bashrc includes the global file as a source, like so:

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

My current workaround uses grep to output the global file, sans offending line, into a local file and use that as a source.

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

Is there a way to do include a grepped file like this without the intermediate step of creating an actual file? Something like this?

. grep -v mesg /etc/bashrc > ~/.bash_global

解决方案

lose the cat, its useless

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

the <() syntax is called process substitution.

这篇关于使用grepped文件作为bash中包含的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆