Variable Scopes
-
Session Scope
- Variables declared in the terminal are valid only during the session.
- They are removed when the session ends.
$ X=10 $ Y=20
-
User Scope
- Variables declared in the
.bashrcfile are available for all sessions of the current user. - These variables are inaccessible to other users.
- Variables declared in the
Example .bashrc snippet:
export GUEST=Dhoni
export FRIEND=Sej- System Scope
- Variables accessible to all users and sessions.
- Declared inside
/etc/profile, requiring root permissions to edit.
Example /etc/profile snippet:
export NAME=DURGA
export COURSE=PYTHON