I have a few custom bash functions that are defined is some file and are made available to me in regular terminals via the line

. "/path/Custom Bash Functions.sh"

in my ~/.bashrc. However, Emacs does not recognize them.

I don't really care whether they are available in any terminal emulator inside Emacs. I only care about them working when I hit M-!.

This answer suggests setting shell-command-switch to "-ic" (adding switch i to the default). However, all this seemingly results in is that the output of all commands I execute via M-! are preceded by:

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

I still can't execute custom bash functions. Auto-complete for them doesn't work either.

Maybe this is because I use a newer version. I use the latest version on the master branch of Emacs' git repo (pulled the latest changes and installed them less than 2 hours ago).

  • 1
    What -i does is to source ~/.bashrc (assuming you use/bin/bash as your shell). So you can put your custom functions in that file, or source your custom functions file from there. That's probably a good idea so you can have your custom functions in a shell without having to source it explicitly every time. The complaints that bash issues however in the -i case probably arise from how emacs sets up the process and probably cannot be avoided.
    – NickD
    Commented Nov 2, 2018 at 17:42
  • 1
    Adding -i should work. Try adding -ix and post the complete output, preferably with a shorter .bashrc that reproduces the problem. Commented Nov 2, 2018 at 19:22
  • You're right. Now it works. Thank you. Maybe I simply mistyped my custom command or something in my init file or .bashrc was messing with what I tried to do. Anyway, it works now. However, there still is no auto-complete. I have to type out the entire command. Should auto-complete work? I tested it with emacs -Q and it behaves in the same way: The command works (after evaluating (setq shell-command-switch "-ic")) but it's not auto-completed when I hit <kbd>Tab</kbd>.
    – UTF-8
    Commented Nov 5, 2018 at 18:34
  • Emacs behaved really weird today. I just figured out that that was because of these two lines that are printed. I use custom functions that run commands and work on their outputs. Because those two lines were included in those outputs, my functions got confused. I had to undo the change of adding the i switch.
    – UTF-8
    Commented Nov 7, 2018 at 15:04

1 Answer 1


I just put my desired alias(es) in .zshenv instead of .zshrc, so that Emacs would pick up on the alias for sure, regardless of whether the shell was interactive. My main reason for doing this was because when I set shell-command-switch to "-ic", I ran into trouble with the output of M-& because it spawns asyncrhonous subprocesses. For example, running du -sh on a directory via dired-do-async-shell-command (or &) yields the following output:

[1] 12345
100M    directory_name
[1]  + done       du -sh directory_name

As you can see, there is extraneous output surrounding the actual output of du -sh. This is apparently due to it running as an interactive shell. So I instead just gave up on making it interactive and placed my desired alias into .zshenv instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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