Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

Environment and Path Setting in Linux

YASH PAL, 3 June 202328 May 2024

Environment and Path Setting in Linux – Bash shell is used for various purposes under Linux. How do you customize the shell environment variable under Linux operating systems?

You can use shell variables to store data, set configuration options, and customize the shell environment under Linux. The default shell is Bash under Linux and can be used for the following purposes:

  1. Configure the look and feel of the shell.
  2. Set up terminal settings depending on which terminal you’re using.
  3. Set the search path such as JAVA_HOME, and ORACLE HOME.
  4. Set environment variables as needed by programs.
  5. Run commands you want to run whenever you log in or out.
  6. Set up aliases and/or shell functions to automate tasks to save typing and time.
  7. Changing bash prompt.
  8. Setting shell options.

You can use the following commands to view and configure the environment.

Display Current Environment in Linux

To display the current environment, type the following command:

$ set

BASH =/bin/bash
BASH_ARGC = ()
BASH_ARGV = ()
BASH_LINENO = ()

Note – There are other values available in the environment depending on your system. we are not displaying the whole values here.

The $PATH defines the search path for commands. It is a colon-separated list of directories in which the shell looks for commands. The $PS1 defines your prompt settings. see the list of all commonly used shell variables for more information. you can display the value of a variable using the printf or echo command.

$ echo “$HOME”
OR
$ printf”%s\n” $HOME

Sample output

/home/ram

You can modify each environmental or system variable using the export command. Set the PATH environment variable to include the directory where you installed the bin directory with Perl and shell scripts:

export PATH = $ { PATH)/home/ram/bin
OR
export PATH=${PATH}:${HOME}/bin

Pathnames

Every file has a pathname, which is a trail from a directory through part of the directory hierarchy to an ordinary file or a directory. Within a pathname, a slash (/) to the right of a filename indicates that the file is a directory file. The file following the slash can be an ordinary file or a directory file. The simplest pathname is a simple filename, which points to a file in the working directory.

Absolute Pathnames

An absolute pathname starts with a slash (/), which represents the root directory. The slash is followed by the file’s name located in the root directory.

setting environment and path in linux

An absolute pathname continues, tracing a path through all intermediate directories, to the file identified by the pathname. String all the filenames in the path together, following each directory with a slash (/). This string of filenames is called an absolute pathname because it locates a file absolutely by tracing a path from the root directory to the file.

The part of a pathname following the final slash is called a simple filename, or basename. the above figure shows the absolute pathnames of directories and ordinary files in part of a filesystem hierarchy.

environment and path setting in linux

Relative Pathnames

A relative pathname traces a path from the working directory to a file. The pathname is relative to the working directory. Any pathname that does not begin with the root directory (represented by /) or a tilde (~) is a relative pathname. Like absolute pathnames, relative pathnames can trace a path through many directories. The simplest relative pathname is a simple filename, which identifies a file in the working directory.

Computer Science Tutorials Linux computer scienceLinux

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes