I'm using GNU Emacs 26.3 on a Windows 10 system (Virtualbox guest on Mac).

The following grep command inside emacs fails:

grep -i -n -d skip -e temp_ *

with this error:

grep -i -n -d skip -e temp_ * NUL
agrep: NUL: No such file or directory

Grep exited abnormally with code 2 at Mon Mar 23 12:27:03

If I run the command in the wsl shell it works.
The following grep command inside emacs also works fine:

grep -i -n -d skip -e temp *

Note: the missing _ at the end.

I tried escaping the underscore with \ and \\, nothing helped.

Any ideas? Thanks a lot.

Edit: FYI: I'm using the following shell command, which works fine for other grep, make, etc. commands:

(setq explicit-shell-file-name "C:/Windows/System32/bash.exe")
(setq shell-file-name explicit-shell-file-name)

as for Tobias request: I run the 'grep command via my shortcut F5:

(global-set-key [f5] 'grep) 


Run grep (like this): grep -i -n -d skip -e temp_ * 
  • What do you mean by "inside emacs"? How do you run the command? Please give the key sequence you use before typing the shell command or the major mode of the buffer you are in when typing the shell command. Maybe, you can even give a recipe for reproducing the problem starting from emacs -Q. – Tobias Mar 23 '20 at 12:15
  • I start the emacs using: runemacs.exe. So I did not really manage of invoking grep via command line runemacs -Q – HeyMan Mar 23 '20 at 14:34
  • AFAIK explicit-shell-file-name has nothing to do with grep. What is the value of shell-file-name that is really used? – Tobias Mar 23 '20 at 17:02
  • I added the 2nd command which I use, thanks for the pointer. – HeyMan Mar 24 '20 at 7:40
  • From my point of view it is a bit awkward to use the WSL version of bash when you are <stroke>within WSL</stroke> -- no actually you are in Ubuntu or whatever Linux Distro you chose in your WSL settings. Why don't you keep the default settings? Comment out the settings for explicit-shell-file-name and shell-file-name restart Emacs and try again. I assume that /bin/sh is used in that case. If you want bash syntax you could set explicit-shell-file-name to /bin/bash. – Tobias Mar 24 '20 at 7:51

Based on @Tobias valuable feedback it is now working. See the comments above for details. Here is the summary:

I was using the mingw-version of Emacs (means the windows version of emacs). Now I installed an X-Server and emacs in my wsl Ubuntu shell and now use this emacs instead. And the problem no longer occurs.

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.