back

by JNRowe·2y ago·view on hn ↗
What felt like an initial thirty second throwaway comment yesterday has turned in to a pile of replies that feel like a poorly conceived Ted talk now, forgive me for that.

The dividing line between variables that should be prefixed by export are ones that are generally useful to child processes and ones that are not.

For example, $PATH is useful and should be exported. You probably want scripts you start to have access to all the things you have installed, not just the locations of the default search path:

    PATH= =zsh -fc 'print -l $path'
$HISTFILE/$PROMPT/etc control current shell behaviour and are unlikely to be of any use to child processes executed by the shell, and do not need to be exported. Remembering, of course, that they'll be set by any new interactive shells anyway as they too will read their startup files when launched.

Oftentimes it doesn't make much difference. However, some such as $CDPATH can cause non-obvious bugs when they're exported, and some such as $HISTFILE can cause data corruption or even loss when the planets align against you.

1 comments
Hah no problem.

There was just enough time after your talk for 1 more question from the audience:

For my zshrc that you poked around in, is this issue related specifically to HISTFILE or all of the history related env vars?

All four of the $HIST* parameters are perfectly functional without export.