Simple solution of Linux variables

Source: Internet
Author: User

Variable


1. Custom Variables

① variable = variable value

X=5

Name= "Jie Chao" (the symbol in double quotes has meaning, the symbol in single quotation marks has no meaning)

② Call $name

③ Variable Overlay

x=123,x= "$x" 456

④ Delete variable unset variable name (without $ symbol)

⑤ View all variable set

2. Environment variables

① Setting Environment variables

Export variable = variable name

② Viewing environment Variables env

③path variable, the path of the system search command

3. Positional parameter Variables

① $n N=0..9:n is a number, and $ A represents the command itself, $1-$9 represents the first to nineth arguments, and more than 10 arguments are enclosed in curly braces, such as ${10}, to pass the input parameters to the script. Cases:

#!/bin/bash

Num1=$1

Num2=$2

sum=$ (($num 1+ $num 2))

Echo $sum

②$* returns the input parameters to the script and considers all parameters as a whole

③[email protected] Returns the input to the script parameter, treats each parameter differently

④$# returns the number of input-to-script parameters

#!/bin/bash

echo "\$* can shu Shi: $*"

echo "\[email protected] can shu Hai shi: [email protected]"

echo "\$# can shu ge shu shi: $#"

4. Pre-defined variables

①$? Determine if the previous command was executed correctly, the return value of 0 indicates correct

②$$ PID of the current process

③$! The last process number running in the background

5. Accept keyboard Input

read [options] [variable name]

-P: Prompt information

-T: Number of seconds to wait for input, over wait time program terminates

-N: Directly subject to the specified number of characters

-S: input is not displayed (password input)

Eg:read-p "Please input your name:"-T-Name

Read-p "Please input secret:"-t 30-s Age


Simple solution of Linux variables

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.