How to run shell commands in emacs on ubuntu while

2019-04-28 05:11发布

问题:

I installed emacs in ubuntu (using sudo apt-get install emacs). I am havine the problem that when I try to run a shell command from within emacs (for example M-! ls) the output is preceded by this:

bash: cannot set terminal process group (-1): Invalid argument
bash: no job control in this shell

In my .emacs I have the option (setq shell-command-switch "-ic") . This is so that I can presumably use my aliases as well as commands. This has not given me issues at work and it lets me use my aliases. How can I use my aliases but avoid this problem?

回答1:

I guess that by setting your shell-command-switch like that, you are executing code paths in your .profile or system profile which depend on job control in shells.

I would fix this error by defining the aliases you need in the correct code paths so that that appear in shells which are not started with -i

You could try to swap -i with --rcfile .aliases or something similar so that alias in emacs does not differ from alias in your login shells. If your .bashrc has important stuff for your work, create a file like .bashrc.emacs with the content

source .bashrc
source .aliases

and point to that file with --rcfile .bashrc.emacs in your (setq) instruction.

Where did you define your aliases? Ubuntus .bashrc reads .bash_aliases and that should happen also to non-interactive shells.