tags:

views:

474

answers:

3

I have some aliases and functions defined in ~/.bashrc.

I start emacs from a terminal window using emacs -nw

When I execute M-x shell-command, the aliases and functions from ~/.bashrc are not available, but give a "command not found".

I've googled quite a bit but all the posts I come across say, if I understand them correctly, that ~/.bashrc is the place where this should work (rather than ~/.profile or ~/.bash_profile).

What am I missing?

+5  A: 

Aliases are available only in interactive shell - a snapshot from bash man page:

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below).

dimba
+1  A: 

If you start Emacs from an interactive shell (in which .bashrc, etc. have executed), then the commands from your .bashrc should be available for both shell-command and shell, at least that's how it works for me.

But yeah as the other answer says, there is not real way to get a .bashrc environment in emacs. There are some documentation about a .emacs_bash file, but that never worked for me.


Okay misread your question here. If you are looking for functions and aliases instead of commands by changing paths in .bashrc, the non-interactiveness is the problem. I guess you can change the default argument to shell-command (take a look at explicit-bash-args) to make bash interactive, but that probably has unintended consequences.

polyglot
A: 

prepend a sudo when starting emacs and i'm not able to access the exported variable in bashrc. Leave out the sudo and I"m able access it. M-! eg. echo $P4PORT Any reason why ? and the variables are exported in both the .bashrcs in my home directory and in the /root/.bashrc. Any suggestions ?

maindoor