4
  • System: macOS 10.12
  • Tmux version: 2.6

As a macports user, I have /opt/local/bin at the beginning of my PATH. However, when starting tmux, it uses /bin/bash instead of /opt/local/bin/bash, indeed, the SHELL variable also points there. This confuses me and causes some .bashrc settings to break because the version is outdated.

I know I can set the path to tmux's default shell set-option -g default-shell, but I use my .tmux.conf on different systems, so it should be OS-agnostic and simply use the shell one would get when executing bash.

I have all my settings in .bashrc and source this file in .bash_login und .bash_profile, so my PATH should be available to tmux.

How can I solve this?

It seems that SHELL is always /bin/bash, not sure why. My terminal is configured to start /opt/local/bin/bash -l at startup.

2
  • "However, when starting tmux, it uses /bin/bash instead of /opt/local/bin/bash, indeed, the SHELL variable also points there." – Which of the two paths do you refer to by "there"? Do you mean the SHELL variable after tmux and the new shell starts? or before? (i.e. in the old shell, if you invoke tmux from already existing shell). Do you use tmux as a login shell? If not, what is your login shell and what is the SHELL variable in it? (before you invoke tmux from it). Commented Dec 24, 2017 at 11:47
  • It seems that SHELL is always /bin/bash, not sure why. My terminal is configured to start /opt/local/bin/bash -l at startup.
    – oarfish
    Commented Dec 24, 2017 at 12:10

1 Answer 1

2

This is what man 1 tmux says about default-shell in Linux. I expect tmux in macOS to behave similarly:

default-shell path

Specify the default shell. This is used as the login shell for new windows when the default-command option is set to empty, and must be the full path of the executable. When started tmux tries to set a default value from the first suitable of the SHELL environment variable, the shell returned by getpwuid(3), or /bin/sh. This option should be configured when tmux is used as a login shell.

As you can see, none of these methods uses $PATH. Additionally from bash manual:

SHELL

The full pathname to the shell is kept in this environment variable. If it is not set when the shell starts, Bash assigns to it the full pathname of the current user’s login shell.

Either way it's your login shell what matters and it's not /opt/local/bin/bash. You may consider overwriting SHELL with $BASH in your .bashrc:

SHELL="$BASH"

Note: I haven't tested this against side effects. There's one peculiarity (at least in my Kubuntu) with this. If tmux is already running for your user then changes to SHELL will not affect additional invocations. This is because an additional tmux invocation works along with the first tmux and it's the first tmux that handles everything (I can see this with pstree); its environment doesn't change when you invoke an additional one.

However this way of invoking tmux should honor your $PATH, regardless of $SHELL etc.:

tmux new-session bash
3
  • Setting the SHELL variable solves my problem for now.
    – oarfish
    Commented Dec 24, 2017 at 16:32
  • you set SHELL variable in what file? @oarfish
    – karakays
    Commented May 25, 2018 at 12:37
  • In .bashrc which I'm sourcing in .bash_login to have the stuff be read by tmux.
    – oarfish
    Commented May 29, 2018 at 6:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .