Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Linux Basics

105 / 107

Environment variables

Unix shell provides environment variables. These variables are used to control the functionality of our whole environment (systemwide) and not only to the current shell. The one restricted only to a particular shell are called shell variables.

To see the entire list of environment variables, use:

set

These environment variables can be used by the shell, programs or commands.

For example, the $PS1 variable is used by the shell to display the prompt. To change your prompt, you can try:

OLDP=$PS1
PS1='MyPrompt: '

Please note that if you change your prompt it might make you uncomfortable but you can execute any commands as usual. Here is the snapshot of me executing pwd and whoami commands from new prompt.

bash-4.2$ OLDP=$PS1
bash-4.2$ PS1='MyPrompt: '
MyPrompt: pwd
/home/sandeepgiri9034
MyPrompt: whoami
sandeepgiri9034
MyPrompt:

To restore back to the previous prompt, try:

PS1=$OLDP

There are many other environment variables with various utilities. For example, the environment variable $PATH is a list of directories separated by a colon. It is used by the shell to find the file corresponding to a command.


No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...