1

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
Andrew
  • 36,541
  • 13
  • 67
  • 93
  • Why not just use `mesg n` in your ~/.bashrc? In any case, you can specify the file to grep or redirect grep's stdin; don't use cat uselessly. –  Mar 16 '10 at 07:31
  • 'Grokked' is not the past tense of 'grep'. http://www.google.com/search?q=define:grok –  Mar 16 '10 at 07:32
  • Changed to grepped… `mesg n` still seems to force the terminal into some type of tty session – Andrew Mar 16 '10 at 07:35

4 Answers4

6

lose the cat, its useless

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

the <() syntax is called process substitution.

ghostdog74
  • 327,991
  • 56
  • 259
  • 343
2
. <(grep -v mesg /etc/bashrc)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

I suggest to call mesg n :)

Drakosha
  • 11,925
  • 4
  • 39
  • 52
  • Calling `mesg n` after `mesg y` has been called globally still seems to force it into tty mode. I'm still getting `stdin: is not a tty ` as an error… – Andrew Mar 16 '10 at 07:29
0

From memory, but something like

grep -v mesg /etc/bashrc | eval

should do the trick

Since i'm not sure eval will read stdin, you may need to rephrase it into

eval `grep -v mesg /etc/bashrc`
Isak Savo
  • 34,957
  • 11
  • 60
  • 92
  • But then how can I use that as a source with the `.` command? `. eval `stuff`` doesn't work… – Andrew Mar 16 '10 at 07:32
  • You don't need to source it.. eval will essentially do the same thing – Isak Savo Mar 16 '10 at 07:44
  • 1
    have you tried ? Create a simple file, called "testprofile" and inside it, `export TEST="something"`. now, do the `grep` and `eval` on `testprofile` and see if $TEST has the value. – ghostdog74 Mar 16 '10 at 07:48