Skip to main content

How to set an environment variable (secret, password, etc.) in a way so its value is not saved to the Bash history.

# The password will be stored in the ROOTPASS variable
# The -s option tells read not to echo the typed characters, so nobody can look it up while you type it. -p indicates prompt.
read -s -p "Enter password:" ROOTPASS

# If you need the variable to be available in subshells, then you must export it:
export ROOTPASS