Hide Environment Variables From Your History

Here’s a neat little trick I learned today; if you want to hide the value of an Environment variable from your history/logs, put a space before the export command!

Photo by Arnold Francisca on Unsplash

Here’s an example:

export NATHAN=foo
echo $NATHAN
foo
export NATHAN=bar
echo $NATHAN
bar
history
10083 export NATHAN=foo
10084 echo $NATHAN
10084 echo $NATHAN

Particularly helpful if you are using secrets as Environment variables and you don’t want these to make it through to centralised logging platforms.

Enjoy!

Back to Blog