(Boring update: it seems that this persists with macOS 15 Sequoia.)
Recently (possibly with the Sonoma update, but possibly even more recently than 14.0), Apple Terminal has been giving the following error on startup (when macOS is set to restore windows, i.e., when System Settings > Close windows when quitting… is unset):
date: illegal time format
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
[-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
[[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]
-bash: Saving: command not found
or, in the case of zsh
,
/Users/jaffe/.zsh_sessions/<random hex guid>.session:2: command not found: Saving
(Sometimes the error messages are somewhat different — the problem is clearly somewhat "non-deterministic" due to whatever race condition is happening.)
Since originally posting this question (see updates below), it has become clear that the error appears to happen in multiple versions of macOS, on Intel and Apple Silicon. It does not appear to be due to installed software or config files.
I have traced this to an error coming from /etc/bashrc_Apple_Terminal
(or /etc/zshrc_Αpple_Terminal
) which is largely concerned with saving and restoring sessions for the various terminal tabs and windows. (Most of the following will specifically refer to the symptoms with bash
but it’s similar for zsh
.)
It comes from the lines
if [ -r "$SHELL_SESSION_FILE" ]; then
. "$SHELL_SESSION_FILE"
rm "$SHELL_SESSION_FILE"
fi
On shell startup, this snippet runs, and then deletes, "$SHELL_SESSION_FILE"
, which is written at shell exit by the following lines:
if [ -n "$SHELL_SESSION_FILE" ]; then
echo -ne '\nSaving session...' >&2
(umask 077; echo 'echo Restored session: "$(/bin/date -r '$(/bin/date +%s)')"' >| "$SHELL_SESSION_FILE")
declare -F shell_session_save_user_state >/dev/null && shell_session_save_user_state
shell_session_history_allowed && shell_session_save_history
echo 'completed.' >&2
fi
The error occurs because $SHELL_SESSION_FILE
incorrectly contains the following text:
Saving session...echo Restored session: "$(/bin/date -r 1698759014 Saving session...)"
rather than echo Restored session: "$(/bin/date -r 1698759014)
For some reason, the Saving session...
text is appearing in the file (twice!) -- it is being sent to "$SHELL_SESSION_FILE"
rather than stderr (via >&2
).
I think I didn't make any changes to cause this, but perhaps I am wrong. The directory ~/bash_sessions/
seems to have recent files with this error, and slightly older files (as recent as yesterday!) which don't. I regularly update various packages with homebrew, and I have recently installed Python 3.12 from python.org, but I can't see how they could reach into the guts of shell startup.
Update: In fact, I see this even with a new user, and even if I use zsh rather than bash! (Apple Terminal has very similar code for session history management under zsh.) So it seems that some other recent change to my system is causing this. But I suspect it's not simply a Sonoma problem, since it does not appear to be widespread. Yikes!
Update 1a: Note that the code is run via trap shell_session_update EXIT
. The error only seems to happen when I exit the shell by quitting Terminal.app, but not when I just use the exit
command. (And I've even tried explicitly sending various signals to the shell via kill -n
, but I can't seem to induce the error that way.)
Update 2: At least one other person is seeing this! Perhaps this indicates an issue with VS Code?
Update 3: After some back and forth in the comments below, it is clear that the error spans multiple versions of macOS on both Intel and Apple Silicon architectures, and we seem to have eliminated VS Code and possibly Python (we seem to be using different versions and installers) as the cause; I have removed /opt/homebrew
and rebooted and still seeing the issue. Is it possible that any of these things somehow "pollutes" the environment -- e.g., /etc/
-- in some way that remains in place?
Update 4: Inspired by an interaction over on TidBits, I tried using Howard Oakley's excellent sandboxed lightweight VM, ViableS. I installed nothing, nada, zip, and added no files to ~/
or anywhere else. But after starting and restarting Terminal.app with a few tabs, and ensuring that "close windows when quitting" is unset, I immediately got the message
/Users/jaffe/.zsh_sessions/<random hex guid>.session:2: command not found: Saving
This seems to point, nearly conclusively, to a macOS bug. But I still don't understand how there are people reporting not seeing it.
Is anyone else seeing this? Is anyone explicitly not seeing it? Any ideas what's happening (or even debugging suggestions)?
I've asked a more specific version of this question over on Unix & Linux SA.