Bash Variables
In the bash shell, variables are used to store values. Variables can be declared and assigned values using the following syntax:
variable_name=value
For example:
name="Shubham Kumar Gupta"
To reference the value stored in a variable, prefix the variable name with a '$' symbol.
echo "My name is $name"
- In bash, variables can store string, integer or floating-point values.
- Variable names are case-sensitive.
- Varibale names can only contain letters, numbers, and underscores and they must start with a letter or an underscore.
How to change $PATH variable
- The $PATH variable in bash defines the search path for executables.
- We can change it by modifying the contents of the $PATH environment variable.
Few ways to modify the $PATH variable in bash:
- Temporarily modify $PATH for the current shell session:
PATH="$PATH:/new/directory"
- Permanently modify $PATH for the current user:
echo 'export PATH="$PATH:/new/directory"' >> ~/.bashrc
- Permanently modify $PATH for the system-wide shell:
echo 'export PATH="$PATH:/new/directory"' >> /etc/environment
- In each of the above examples, replace /new/directory with the path to the directory you want to add to the $PATH variable.
- After modifying the $PATH variable, you may need to log out and log back in or restart your terminal session for the changes to take effect.
Top comments (0)