8. Environment Variables 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.