Skip to content

Latest commit

 

History

History
104 lines (62 loc) · 2.62 KB

01.Built-in_environment_variables.md

File metadata and controls

104 lines (62 loc) · 2.62 KB

Built-in Environment Variables in Linux Scripting

Environment variables are key-value pairs that store information about the system environment. In Linux scripting, several built-in environment variables provide useful information and configuration settings. This tutorial will guide you through the usage of some common built-in environment variables in a Linux environment.

1. $HOME

The $HOME variable stores the path to the user's home directory.

echo "Your home directory is: $HOME"

This will display the path to your home directory.

2. $USER and $LOGNAME

These variables store the name of the current user.

echo "Current user: $USER"
echo "Login name: $LOGNAME"

These will display the current user's name and login name.

3. $PWD

The $PWD variable stores the current working directory.

echo "Current working directory: $PWD"

This will display the path to the current working directory.

4. $PATH

The $PATH variable contains a colon-separated list of directories where the system looks for executable files.

echo "Current PATH: $PATH"

This will display the directories included in the current $PATH.

5. $SHELL

The $SHELL variable stores the path to the user's default shell.

echo "Your default shell: $SHELL"

This will display the path to your default shell.

6. $TERM

The $TERM variable contains the type of terminal being used.

echo "Terminal type: $TERM"

This will display the type of terminal.

7. $HOSTNAME

The $HOSTNAME variable contains the name of the host (computer) in the network.

echo "Hostname: $HOSTNAME"

This will display the hostname of the system.

8. $UID and $EUID

These variables store the user's real and effective user IDs, respectively.

echo "Real User ID: $UID"
echo "Effective User ID: $EUID"

These will display the real and effective user IDs.

9. $RANDOM

The $RANDOM variable generates a random integer between 0 and 32767.

echo "Random number: $RANDOM"

This will display a random number.

Conclusion

Built-in environment variables in Linux scripting provide valuable information about the system configuration and the user environment. Understanding and utilizing these variables can enhance the functionality and flexibility of your scripts. Experiment with these variables to tailor your scripts to specific system contexts and user environments.