Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variable change in shell but won't export

I am having issues with setting permanent environment variables in my shell. For example

HISTSIZE=0
export HISTSIZE
echo $HISTSIZE

The variable will change in the shell. But if I open another tab or close and reopen the shell the variable reverts to its original value of 1000.

I have also tried sourcing the variable with a script written in ~/.bash_profile. But it leaves the same issue of the variable only working in that specific shell. How can I create a permanent change?

like image 805
Dre Avatar asked Nov 14 '25 21:11

Dre


1 Answers

If you open a new tab, the parent process of the new shell isn't your current shell, but your terminal emulator, so exporting HISTSIZE doesn't affect the environment of the new shell.

Since HISTSIZE is only used by the shell itself, there's no need to export it at all. Set its value in .bashrc so that any new interactive shell gets the value initialized.

HISTSIZE=0

If your terminal emulator is configured to start a login shell (common on macOS, I assume much less so in Linux), .bashrc won't be used. In such a case, I recommended adding . .bashrc to the very end of your .bash_profile, so that an interactive login shell is initialized the same as an interactive non-login shell.

like image 147
chepner Avatar answered Nov 17 '25 10:11

chepner