13

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?

10

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.

  • This didn't work for me. – Didier A. Aug 18 '18 at 9:07
  • 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 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 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.