0

I am using Emacs (config file) on macOS Monterey (12.5).

There is something that I do not understand. After being queried on a specific version of the program called sdkman sdk, eshell and macOS default terminal present different outputs!!

On MacOS default terminal:

Last login: Mon Aug  1 16:39:07 on ttys000
pedro@Pedros-MacBook-Air ~ % cd projects/learn-cljs 
pedro@Pedros-MacBook-Air learn-cljs % sdk v

SDKMAN 5.15.0
pedro@Pedros-MacBook-Air learn-cljs % 

Now, eshell returns a different output:

Welcome to the Emacs shell

 ~ $ cd projects/
 ~/projects $ cd learn-cljs/
 ~/projects/learn-cljs $ sdk -v
sdk: command not found
 ✘ ~/projects/learn-cljs $ 

I am new to macOS but I have been using Emacs for awhile in Linux machines. I was shocked by this behavior. I have never seen such asymmetry.

I know eshellhas limited behavior compared to the default terminal even in Linux(for instance, htop does not work - by design). But this was a big surprise.

What does it mean? Eshell does not work well in macOS? Anyway to explain the problem? A bug?

1 Answer 1

1

Eshell is a shell. It is true that programs that need a terminal, such as htop, won’t work in Eshell. However, that is a separate issue.

When you run a command in a shell, it is customary for the shell to first match the command name against its list of built–in commands, and then to search for executable programs in a configured set of directories. By convention, the list of directories to search is stored in an environment variable called PATH. Most users will set this variable by editing a shell startup file, and most operating systems provide some kind of default value that will be used when the user hasn’t done this yet.

But different shells have different startup files. Anytime you try out a new shell, you will find that your customizations from your old shell aren’t there, because they live in a startup file that your new shell doesn’t know about. This is a good thing, because the command syntax and available customizations might differ greatly between shells.

The default shell on OSX is either bash or zsh (I don’t use OSX so I don’t know for sure which.) Bash looks for ~/.bashrc as a startup file, and zsh looks for ~/.zshrc

Eshell doesn’t have a separate startup file; it just uses variables which can be set or configured as part of your Emacs environment. The values of those variables come from your Emacs init file, which is usually ~/.emacs.d/init.el

To control the PATH in Eshell, customize the exec-path variable. You can do this by tying M-x customize-variable and then entering exec-path when prompted.

¹: Naturally this is greatly simplified; they both look for multiple files. Check their manpages for the details.

²: Also simplified; see the Emacs manual for details.

6
  • Thanks. Actually, the default of macOS (previously called OSX) is zsh but bashis also available. Also, the program looks for the .bash_profile file not .bashrc. Aug 2 at 15:18
  • After doing a describe-variableon exec-path, this is what I get: exec-path is a variable defined in ‘C source code’. Its value is ("/Users/pedro/.nvm/versions/node/v8.0.0/bin" "/Users/pedro/.sdkman/candidates/java/current/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/sbin" "/sbin" "/Applications/Emacs.app/Contents/MacOS/bin-arm64-11" "/Applications/Emacs.app/Contents/MacOS/libexec-arm64-11" "/Applications/Emacs.app/Contents/MacOS/libexec") Aug 2 at 15:29
  • 1
    You’re trying to let it find the sdk program, so you need to add whatever directory that program lives in to the list.
    – db48x
    Aug 2 at 20:41
  • 1
    Also, in re the difference between .bash_profile and .bashrc: I said that I was simplifying things :)
    – db48x
    Aug 2 at 20:42
  • 1
    Oh, and if you don’t know what directory sdk is in, go to the shell where it works and run type sdk. It will tell you that sdk is hashed (/some/path/to/sdk). That’s the directory you want to use.
    – db48x
    Aug 2 at 20:46

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.