Environment variables play a crucial role in system configuration and application behavior. They store information that helps programs and the operating system interact effectively. In this article, we will explore how to write a shell script to list all environment variables and their respective values.
Create file using the nano
text editor, run:
nano list_environment.sh
Write the Script
Inside ‘list_environment.sh,’ write the following shell script:
#!/bin/bash
# Use 'env' command to list all environment variables
env
This script utilizes the env
command to display a list of all environment variables and their corresponding values.
Save the file and exit the text editor (e.g., in nano
, press Ctrl + O
to save and Ctrl + X
to exit).
Before running the script, make it executable using the following command:
chmod +x list_environment.sh
Now that the script is executable, you can run it to list all environment variables and their values:
./list_environment.sh
The script will display an extensive list of environment variables and their associated values, which can be useful for system administration, debugging, or understanding how your system is configured.
Read more on Shell and Linux related articles
Other urls to refer