Introduction
Variables, including environment variables, are fundamental elements in computing with numerous critical roles:
- Data Handling: Variables serve as containers in memory to store and manipulate data, enabling programs to work with values throughout their execution;
- Dynamic Adaptability: By utilizing variables, programs achieve dynamic behavior, allowing them to flexibly adjust to various inputs and conditions;
- Readable and Maintainable Code: Assigning meaningful names to data using variables enhances code readability, making it easier for developers and maintainers to understand and work with the code;
- Code Reusability: Variables promote code reusability by storing data in one place that can be referenced and reused multiple times, reducing redundancy and promoting efficient programming practices;
- Parameter Passing: Crucial for data exchange within a program, variables facilitate passing information between different parts of a program or functions, enabling functions to receive input and return results to the calling code;
- Configuration Management: Environment variables, in particular, are valuable for storing configuration settings and system—wide information, providing a convenient method to modify program behavior without altering the source code.
Environment variables, play a pivotal role in programming, enabling data storage, program behavior adjustment, and code readability. They are indispensable in software development and system administration, ensuring efficient and adaptable computing practices.
Type of environment variables
There are three types of environment variables and divide by scope of applying in the entire operating system. First of all, we consider local environment variables. They represent cell of memory that create by current session and don't write into the configuration files. Instead of this they storage in the cache memory and delete by event of close connection and log out by profile via special commands.
If you want to continue use that variables or you needed to save processes in work status, you can use screen utility. They make virtual terminal and allows to detach of system. Let's have a look how to manage that type of variables: for create, delete and change.
Also you can display variable by the command below:
That command set local environment variable for current session, however, highlight scope of usage that cell of memory. If you set their in utility or in program that will available in the accordance process. When the process terminates, the variable also ceases to exist, and its values are not passed to other processes or new sessions. If you want to change value, you can do it by using the same command as we previous described:
But if you want to delete this variable you need to type this:
Or you can assign empty field for simplify deletion:
However, imagine a situation, that you need to delete for some time you variable and back value as we see before. For that we can run utility, shell and any process with out variables:
Let's scale range of usage and look at the user environment variables, which implement and save every session, in comparison with local environment variables, for one user. Schema of process is similar enough, but now we write that command in the file, which start every time as we login in the system.
So, it's automize process of starting command in the file and make that more simplicity. We can work with two main files: .bashrc which use for the local user configuration and .bash_profile which we use for the remote user connection through SSH protocol. For the last one if they will unavailable at any reason, then system will search .bash_login and .profile. We can find that file by command below:
If you can't find needed file of remote connections variables for user,try to search .bash_login and .profile. Let's edit file and add needed raw:
And add needed variable in the file by the command below:
Save file with command after close text editor:
And last of the considering environment variable it's global, we highlight and remind that names and labels of variables indicate scope of usage. Currently scope covers the entire system from any users. We can edit their file bash.bashrc, environment, profile. They also divide into the several point for specific type of user connection. For example we can modify environment and that affect to all users, in the system independent of their type of connection:
Enter the row below and save file with button combinations Ctrl+O:
Applying changes in the by the command:
For only local connection user we can configure bash.bashrc with the same command for enter:
For only remote connection user with range all system, we can modify profile also using the same command:
For deletion that variables we need consequently delete that variables from all files in which we added that or use unset command as we described before.
And how you can see we don't displayed after that anymore.
Conclusion
The environment variables play a crucial role in computing, offering various benefits to software development and system administration. They serve as containers to store and manipulate data, enable dynamic behavior in programs, enhance code readability, and facilitate code reusability. Additionally, environment variables are vital for parameter passing and configuration management, providing a convenient method to modify program behavior without altering the source code.