4

This must be something very simple, but I can't figure it out. Until recently iTerm always properly sourced .bash_profile which has:

Sellotape:~ mnewman$ cat .bash_profile
## .bash_profile - Make sure that .bashrc and .profile are read

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

if [ -f ~/.profile ]; then
    source ~/.profile
fi

.profile has this important line from MacPorts:

export PATH="/opt/local/bin:/opt/local/sbin:$PATH"

This is what Terminal says:

Sellotape:~ mnewman$ echo $SHELL
/bin/bash
Sellotape:~ mnewman$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

And this is what iTerm says:

Sellotape:~ mnewman$ echo $SHELL
/bin/bash
Sellotape:~ mnewman$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin

iTerm Settings>Profiles>General>Default has: command /bin/bash

(I also tried Login Shell, but that didn't work either.)

What have I done to mess up iTerm?

2
  • Provided that you are really using bash (what does echo $BASH_VERSINFO say?), note that .bash_profile is not necessarily sourced. Have a look at the bash man-page, section INVOCATION, to see under which conditions this file is processed. Nov 27, 2023 at 12:36
  • echo $BASH_VERSINFO returns 3. Now that I have set iTerm to run bash as a login shell everything is working as expected.
    – Buadhai
    Nov 28, 2023 at 0:01

1 Answer 1

6

iTerm does not source your shell startup files. It is a terminal emulator, not a shell.

The shell you run inside iTerm sources your shell startup files.

Further, looking at the value of $SHELL is more or less irrelevant. The contents of $SHELL are what your login shell is, not what shell you currently happen to be in.

Example. My login shell is ksh. However...

$ echo $KSH_VERSION
Version AJM 93u+m/1.1.0-alpha+e9182bd6 2023-09-24   <-- yup, this is ksh
$ echo $SHELL
/usr/local/bin/ksh                                  <-- and $SHELL agreees
$ bash                                              <-- now launch bash
$ echo $KSH_VERSION
                                                    <-- not in ksh any more
$ echo $SHELL
/usr/local/bin/ksh                                  <-- waitaminit!
$ echo $BASH_VERSION
3.2.57(1)-release                                   <-- ah, this *is* bash
$

So.

Bash reads .bash_profile only for login shells. It also doesn't read .profile if it can find .bash_profile, which I've always thought is more than a little broken.

So iTerm is not launching bash as a login shell, which means your particular combination of startup files are not being read the way you expect them to be, while Terminal is.

1
  • Thank you for the clear and concise explanation. I learned a lot and fixed the issue. I appreciate your taking the time.
    – Buadhai
    Nov 27, 2023 at 5:00

You must log in to answer this question.

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