Skip to content

Shell environment persistence configuration

Shell environment persistence configuration refers to the practice of using specific startup files—such as .bash_profile or .bashrc—to initialize environments, define custom variables, and execute commands automatically when a new shell session is started.

Bash Configuration Files

On Unix-like systems and environments such as Git Bash, the configuration workflow typically involves two primary files located in the user's home directory. The system checks for these files using conditional tests to ensure they exist before loading them^[400-devops__02-OS-and-Linux-Basics__windows.md].

  • .profile: The system first tests for this file using test -f ~/.profile && . ~/.profile.^[400-devops__02-OS-and-Linux-Basics__windows.md]
  • .bashrc: The system subsequently tests for this file using test -f ~/.bashrc && . ~/.bashrc.^[400-devops__02-OS-and-Linux-Basics__windows.md]

These commands are often found within a .bash_profile file, which serves as the entry point to source other configuration scripts^[400-devops__02-OS-and-Linux-Basics__windows.md].

Configuration Examples

Environment Variables

Configuration files are commonly used to set environment variables, such as JAVA_HOME and PATH.^[400-devops__02-OS-and-Linux-Basics__windows.md] The following example demonstrates how to append the Java binary directory to the system PATH^[400-devops__02-OS-and-Linux-Basics__windows.md]:

export JAVA_HOME=/c/Users/yu_da/.jdks/openjdk-17
export PATH=$PATH:$JAVA_HOME/bin

Prompt Customization

Persistence configuration also allows for the customization of the shell prompt. In Windows PowerShell 7, this is achieved by defining a prompt function within the Profile.ps1 file^[400-devops__02-OS-and-Linux-Basics__windows.md].

An example configuration alters the prompt display by capturing the current location and formatting it, including specific ANSI escape codes (e.g., \e]9;9) that integrate with terminal features like Windows Terminal^[400-devops__02-OS-and-Linux-Basics__windows.md].

  • [[Environment Variables]]
  • [[Shell Profile]]
  • [[Windows Terminal]]
  • [[PowerShell]]

Sources

  • 400-devops__02-OS-and-Linux-Basics__windows.md