Shell Foundation Part2

Source: Internet
Author: User

Shell Basics

First, the variables in bash

1, the definition of the variable: The variable is the memory unit of the computer, where the stored value can be changed.

2, the variable's setting rule: The variable name cannot begin with the number, the variable's equal sign cannot have the space, the variable value if wants to have the space must enclose in the single quotation mark or the double quotation mark, the variable's default type is the string type, if wants to calculate needs to specify the variable type to be numeric type; The superposition of variables requires the use of double quotation marks "$ variable name" or ${variable name}; If you need to assign the result of the command as a variable value, you need to use an inverse quotation mark or a $ () containing command, and an environment variable to make it easier to distinguish.

3. Classification of variables

User-defined variables (local variables): The user can freely define but only take effect in the current shell.

Environment variables: This variable is mainly to save the data (PATH) related to the system operating environment, can create a new environment variable can also modify the system environment variables (modify the value of the environment variable).

Positional parameter variables: Mainly used to pass parameters or data to the script, the variable name cannot be customized, the function of the variable is fixed and cannot be defined, only the value of the passed variable can be modified.

Predefined variables: are defined variables in bash, variable names cannot be customized, variables are fixed, and positional parameter variables are one of the predefined variables.

4, the SET command is to see the variable, unset variable name is to delete a variable


Second, environment variables (global variables)

1, the definition of environment variables: not only in the current shell can also be effective in its child shell, the environment variable is written to the configuration file will also take effect in all shells.

2. Setting Environment variables

Export variable name = variable value (export means to declare that the variable is an environment variable)

Env is a specialized query environment variable command to declare local variables as environment variables only the export variable name is required.

eg:path=$ "path":/root/sh or path=${path}:/root/sh This is a variable overlay of the PATH environment variable

Three, position parameter variable

1. Parameters and their functions

  


IV. pre-defined variables

1. Parameters and their functions

  

2. Accept keyboard Input

  

Shell Foundation Part2

Related Article

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.