Definition of common linux commands (Day 6) -- shell environment variables

Source: Internet
Author: User
I am too lazy. it seems that I have been lazy and don't want to write a blog at all over the past few days. Later, I thought about the knowledge. First, cure your laziness cancer. second, consolidate your knowledge.

I am too lazy. it seems that I have been lazy and don't want to write a blog at all over the past few days. Later, I thought about the knowledge. First, cure your laziness cancer. second, consolidate your knowledge.


There are two types of Linux variables: System variables, which are written into the memory once the system is started. It can be called in various processes and sub-processes.

One is self-configured Variables. after shutdown, the system crashes after it is started, or the next process is switched off, and the variables cannot be found. This is a local variable.

The above two variables are described in detail on the fifth day.

There is a command for viewing environment variables: env indicates environment [environment.

There are some common constants, such as HOME, SHELL, HISTSIZE, MAIL, PATH, LANG, and RANDOM. All these words are well known, and Gu Ming thinks about them. Therefore, we will not proceed with the explanation.

View the current system constant and all the variables you set. You can run the set command.

Next, let's continue to talk about the differences between the environment variables of env and the custom variables of set: (reference Chapter 11th of laruence linux private dish) the difference between the two lies in whether the variable will be referenced by the quilt process, so what is the parent process and what is the child process. After logging on to linux and getting a bash, your bash is an independent process and the pid is used. Next, any command you run under this bash is derived from this bash, and the executed commands become sub-processes. (Awesome! it's really good to write .)

In my notes on the fifth day, I raised a question: how can I set the variables as environment variables. Now we can use the export command. Export means output, exit, take away, and transport;

This means to change the self-configured variables into environment variables.

:

Global variable (global variable) = environment variable

Local variable (local variable) = local variable

Why can environment variable data be referenced by the quilt process? This is because of the memory configuration. Theoretically:

1. when a shell is started, the operating system allocates an exclusive region to the shell. The variables in this memory can be called by sub-processes,

2. if the export function is used by the parent process, custom variables can be loaded to the memory blocks mentioned above.

3. when loading another shell, it is the promoter process. Leave the original parent process. Sub-shell: imports the memory block of the parent shell environment variable into its own environment variable block.


The preceding variables are a bit interesting. Let's continue to look at more interesting things. If and else.

I remember that when I installed the one-click lamp installation package, I would choose the mysql version and the php version, and set the installation path and default password. At that time, I was curious about how to write such step-by-step guidance. We will see the read command next.

The command syntax is as follows. Read [-pt] variable

This-p command refers to print. You can use the man read command to view details.

This-t indicates the maximum number of seconds that the user can wait. Come on. Let's take a look at how to use it.

The select variable that I followed can be used to obtain whether yes or no is used for input on the keyboard.

The following describes a method for declaring variables. Declare indicates the declaration.

Declare-a declares the meaning of an array. A indicates the event array (array) type.

Declare-I indicates the meaning of an integer, and I indicates an integer)

Declare-x can change the following variables into environment variables. X indicates the export, which may start with x, so it is named after x.

Declare-r can be used to set the variable (variable) to the read-only type. R represents readonly.

If the declare type is not famous, the default type is string.

The numeric budget in the bash environment. by default, only the integer type can be reached.

Below we will use a small chestnut to practice the knowledge points mentioned above.

Next let's take a look at the declare-x usage.

Let's take a look at the declare-r usage.

These options can be used in combination.


This blog is actually written on Monday or Tuesday this week. However, this week's physical and mental states are not very good. Therefore, no blog is continuously updated.

Even though I know that there are big cows in the blog Park, I am not very concerned about this sharing. But we still need to continue.

By the way, let's talk about our own feelings: time will really bring about a huge change like a sansea. Some friends are only suitable for remembering and some others are only suitable for remembering. With the surging tide of time, we have never been washed away. It may become more kind, more sensitive, and more optimistic. In short, they are no longer people in the past. they are placed in the friends list. when the night is full and the night is full, you can see which friends are friends of the past. This is enough. if you can keep in touch for a long time, you must cherish it.

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.