9

How can I start an interactive zsh without running any configuration files like .zshrc?

I tried zsh -d -f -i, but the prompt was the same as specified in ~/.zshrc, so those options don't seem to have worked.

I'm running zsh 5.8 on macOS 10.15.4.

3
  • 2
    Do you make the mistake of exporting your prompt variables?
    – JdeBP
    Apr 10, 2020 at 7:01
  • @JdeBP: Yes, I did. How can I start a new interactive zsh that ignores either all existing exports, or specified existing exports?
    – XDR
    Apr 10, 2020 at 10:52
  • Well, unexport them. typeset +x PS1. Or start it as env - FOO=bar zsh.
    – user313992
    Apr 10, 2020 at 11:52

1 Answer 1

13

zsh -d -f -i is correct for that, though -d (implied by -f) and -i (zsh runs interactively anyway when not given any script/code to run on the command line and stdin is a terminal) would be redundant.

Note however that /etc/zsh/zshenv is still interpreted and I don't think there's any way to disabled that. See info zsh RCS for details.

In your case, PS1 was inherited from the environment. PS1 is one of many environment variables that can also customize the shell.

Note that earliest shells had no rc file, customisation was done with environment variables only (which you'd set in the ~/.profile or ~/.login, interpreted by the login shell).

There are a large numbers of variables used to configure the shell. See:

info zsh 'Parameters Used By The Shell'

for details (note though that for some of them, the value found in the environment is ignored).

Some of those environment variables, like HOME, PATH, SHELL, COLUMNS, LANG, LC_* are used by many other programs than the shell, so it's not a good idea to unset them, or to use env -i to unset them all.

Most of those variables listed in that documentation you would not want to put in the environment, but declare them in your ~/.zshrc instead as normal shell variables. PS1 is one of them. PS1 is used as the prompt customisation variable in many shells, but the syntax varies greatly between shell.

Unfortunately, some GNU/Linux distributions do set and export the PS1 variable in some system start-up file, and define it with a value specific to the syntax of the bash shell (the GNU shell), which means that if you start any shell other than bash in an environment with that PS1, you get a garbage prompt.

To start a shell with PS1 removed from the environment, you can do:

(unset -v PS1; zsh -f)

With some env implementations, you can also do:

env -u PS1 zsh -f

To start it with no environment variable (though as noted above, it's probably not a good idea):

env -i zsh -f

You must log in to answer this question.

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