16

I have the following two lines of code in my init.el file:

(setq shell-file-name "bash")
(setq shell-command-switch "-ic")

I tried executing the following script to get a list of executables using the shell script dmenu_path.

(defun dmenu-path-out ()
  (shell-command-to-string "dmenu_path"))

I see the following error:

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
[
0ad
...

How can I prevent bash from returning that error when using shell-command?

Malabarba
  • 22,878
  • 6
  • 78
  • 163
wdkrnls
  • 3,657
  • 2
  • 27
  • 46
  • Possibly partial duplicate question of https://stackoverflow.com/questions/9670209/cygwin-bash-does-not-display-correctly-in-emacs-shell/52643961#52643961 there seems to be no solution yet if your shell is cygwin's bash – julio Oct 04 '18 at 10:26

2 Answers2

13

The -i flag requests that Bash run in interactive mode, which requires a terminal. The solution is to leave the shell-command-switch variable at its default value, which is just -c.

If you really need to run Bash in interactive mode, you will need to run it in a pseudo-terminal, by using start-file-process with process-connection-type bound to t.

jch
  • 5,680
  • 22
  • 39
  • This didn't work for me. – Didier A. Aug 18 '18 at 09:07
  • 1
    It works for me. As an example, this command launches `gnome-terminal`, runs `echo` and leaves the Bash session running and ready to take new commands: `(start-file-process-shell-command "peekaboo" "*Messages*" "gnome-terminal -- bash -c 'echo Peekaboo!; bash'")`; any output from the Elisp command is sent to the `*Messages*` buffer. Note that I used `start-file-process-shell-command` instead of `start-file-process`, so I don't need to give the path to shell programs. – Arch Stanton Mar 25 '19 at 17:52
0

Did you add -i to get bash to expand aliases? If so, as given in https://stackoverflow.com/questions/12224909, instead include

(setenv "BASH_ENV" "~/.bashrc")

in your .emacs and

shopt -s expand_aliases

in your .bashrc. The former causes your .bashrc to be run on your sub-shells, and the latter allows alias expansion in non-login bash shells.

You can go one better by creating a separate shell script with your aliases and the shopt line, and using that as the BASH_ENV value; that may run faster than your full ~/.bashrc.

  • Can you please summarize the fix detailed there? Otherwise this is essentially a link-only answer and so risks being deleted. – Drew May 29 '19 at 01:19