The Profile File
Part of the Fundamentals section of Coddy's Terminal journey — lesson 64 of 82.
Variables you set and export only last until you close the terminal. To make them permanent, you need to add them to a profile file that runs automatically when you start a new shell session.
The most common profile file is ~/.bashrc for Bash shells or ~/.zshrc for Zsh. These files are shell scripts that execute every time you open a new terminal. You can view your profile file with:
cat ~/.bashrcTo add a permanent environment variable, append an export statement to your profile file:
echo 'export MY_VAR="hello"' >> ~/.bashrcThe single quotes prevent the shell from expanding the variable now, and the appends to the file instead of overwriting it. After adding to the profile, the change won't take effect in your current session. You need to either open a new terminal or reload the file with:
source ~/.bashrcThe source command executes the file in your current shell, applying any new variables or settings immediately. This is how developers customize their terminal environment with personal preferences, shortcuts, and configurations that persist across sessions.
Challenge
EasyAdd a permanent environment variable to your profile file, then reload it to apply the changes.
First, append an export statement to ~/.bashrc that sets a variable called WORKSPACE with the value /home/user/projects. Use single quotes around the entire export statement to prevent variable expansion.
Then, use the source command to reload the profile file so the variable takes effect immediately.
Finally, use echo to display the value of your new WORKSPACE variable.
Your final output should be:
/home/user/projectsHint: Use
echo 'export WORKSPACE="/home/user/projects"' >> ~/.bashrcto append, thensource ~/.bashrcto reload, and finallyecho $WORKSPACEto verify.
Cheat sheet
Environment variables set with export only last until the terminal closes. To make them permanent, add them to a profile file like ~/.bashrc (Bash) or ~/.zshrc (Zsh).
View your profile file:
cat ~/.bashrcAppend a permanent environment variable to your profile:
echo 'export MY_VAR="hello"' >> ~/.bashrcUse single quotes to prevent variable expansion, and to append (not overwrite).
Reload the profile file to apply changes immediately:
source ~/.bashrcThe source command executes the file in your current shell, applying new variables without opening a new terminal.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline