Objective
???? There are environment variables in windows, such as the path we are familiar with ... So, is Linux there?
?
Body
???? The operating system is really not as smart as everyone thinks, but it's stupid.
For example, we enter: LS executes immediately
?
How is the operating system executed? How does it know how to execute LS? Where is the program to be executed?
Environment variables: Simply put, tell the system where to go (folder) to find the executable program according to the command.
?
View environment variables
Echo $PATH (PATH must be capitalized)
?
First, local variables (temporary)
Can be considered a session variable (process level)
1. Assigning values
Myname=fatsnake
PS: String Connection clamp double quotes
Myname=fat
Myname= $myname "Snake"
Print
echo $ fatsnake
Delete
Unset Fatsnake
?
Second, the system environment variable--path
A variable that the system is super-dependent on. When you execute a command, it automatically goes to the folder inside the variable to find " executable program "
?
?
Iii. setting and acquiring environment variables using C language
#include <stdio.h>
#include <stdlib.h>
int main (int argc,char *argv[]) {
?
???? Set Value
???? Putenv ("myname=fatsnake123");
???? Get value
???? Char *getresult=getenv ("myname");
???? printf ("MyName is%s\n", getresult);
?
???? printf ("Path is%s\n", getenv ("path"));
???? int i;
???? if (argc = = 2) {
???????? printf ("%s\n", argv[1]);
???????? if (strcmp (argv[1], "-version") = = 0) {
???????????? printf ("Version god 1.1\n");
????????}
???????? else{
???????????? printf ("%s\n", argv[1]);
????????}
????}
????
???? return 0;
}
?
Four, the experiment
The temporary variables set on the command line are not available in the C language!
Ps: Description is the temporary variable is process level, command line and C language program is two processes.
This mechanism of the system guarantees the process security, that is, the set of temporary variables will not be modified by other programs.
?
End
8. Environment Variables 1