Use of shell (1) variables in Linux, linuxshell

Source: Internet
Author: User

Use of shell (1) variables in Linux, linuxshell

One Variable

Echo $ a: output variable a. If it does not exist, a variable a is created.

Unset a: Cancel variable

1.1 environment variables:

Env: View descriptions of environment variables and common variables

HOME: Your main folder

HISTSIZE: Number of historical commands that can be recorded by the System

PATH: PATH of the execution file query

LANG: modifiable language family

Set: view all variables, including environment variables and custom Variables

PS1: Command Prompt

Export: You can convert custom variables to environment variables.

Language: locale


Keyboard reading, array, and Declaration of 1.2 Variables

Read: read variables from keyboard input

For example, read-p "please input your name:"-t 30 name (after the command is executed, please input your name:) your input value will be included in the variable name, if this parameter is not entered for more than 30 seconds, the system will be disqualified

-P: Followed by a prompt

-T: the number of seconds that can be followed.

Declare/typeset: declare the type of the Variable

Declare [-aixr] variable name

-A: defines variables of the array type.

-I: defines integer variables.

-X: Change the variable after the parameter to the environment variable.

-R: Set the variable to read-only.

Note: The default variable type is "string"

Array: array variable type


Delete, replace, and replace variable content


Variable setting method

$ {Variable # keyword} if the variable content matches the keyword from the beginning, the minimum data that matches the keyword is deleted.

$ {Variable ## keyword} if the variable content matches the keyword from the beginning, the longest matching data will be deleted.

$ {Variable % keyword} if the variable content matches the keyword from the forward data, the minimum data that matches the keyword is deleted.

$ {Variable % keyword} if the variable content matches the keyword from the end to the forward data, the longest matching data is deleted.

$ (Variable/old string/New String) if the variable content matches the old string, the first old string will be replaced by the new string

$ {Variable // old string/new string} if the variable content matches the old string, all old strings will be replaced by the new string









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.