Operations 5 min read

Master Linux Environment Variables: Permanent & Temporary Settings for Bash and Csh

This guide explains how to configure both permanent and temporary environment variables on Linux for different shells (bash and csh), covering per‑user and system‑wide settings, the required configuration files, and practical command‑line examples to verify the changes.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Environment Variables: Permanent & Temporary Settings for Bash and Csh

Linux environment variable configuration can be divided into permanent and temporary variables, and the method depends on the shell type. This article outlines the steps for Bash (/bin/bash) and Csh (/usr/bin/csh) for both per‑user and system‑wide settings.

1. Bash (/bin/bash) – Permanent Variables – All Users / Single User

Step 1: Run echo $SHELL to confirm the current shell.

Step 2: For a single user, add export ORACLE_HOME=/home/oracle/base to .profile in the user’s home directory (create the file if it does not exist).

Step 3: For all users, add the same line to /etc/profile.

Step 4: Execute source .profile (or source /etc/profile) to apply the changes.

Step 5: Verify with echo $ORACLE_HOME.

$ echo $SHELL
/bin/bash
$ vi .profile   # add ORACLE_HOME
export ORACLE_HOME=/home/oracle/base
$ source .profile
$ echo $ORACLE_HOME
/home/oracle/base

2. Bash (/bin/bash) – Temporary Variables

Step 1: Confirm the shell with echo $SHELL.

Step 2: Set a temporary variable using export ORACLE_BASE="/opt/oracle/base". Note that the variable only lasts for the current shell session.

Step 3: Verify with echo $ORACLE_BASE.

$ echo $SHELL
/bin/bash
$ export ORACLE_BASE="/opt/oracle/base"
$ echo $ORACLE_BASE
/opt/oracle/base

3. Csh (/usr/bin/csh) – Permanent Variables – All Users / Single User

Step 1: Run echo $SHELL to ensure you are using Csh.

Step 2: Add setenv ORACLE_HOME /home/oracle/base to .cshrc in the user’s home directory (create the file if needed) for a single user.

Step 3: Apply the changes with source .cshrc.

Step 4: Verify with echo $ORACLE_HOME.

$ echo $SHELL
/usr/bin/csh
$ vi .cshrc   # add ORACLE_HOME
setenv ORACLE_HOME /home/oracle/base
$ source .cshrc
$ echo $ORACLE_HOME
/home/oracle/base

4. Csh (/usr/bin/csh) – Temporary Variables

Step 1: Confirm the shell with echo $SHELL.

Step 2: Set a temporary variable using ORACLE_BASE="/opt/oracle/base". This variable is only valid for the current session.

Step 3: Verify with echo $ORACLE_BASE.

$ echo $SHELL
/usr/bin/csh
$ ORACLE_BASE="/opt/oracle/base"
$ echo $ORACLE_BASE
/opt/oracle/base

(Source: https://www.cnblogs.com/linyfeng/p/10995761.html – © original author)

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

System AdministrationBashEnvironment VariablesCsh
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.