Linux self-Study _shell variable Chapter

Source: Internet
Author: User

Introduction

3000 block of wages and 30000 wages, the gap lies in the latter has the accumulation of life experience, the summary of technical knowledge is also a life experience.


1) What is a shell variable?

A variable is a simple character to replace a complex character.

2) How many shell variables are there?

Environment variables and local variables

3) How are variables defined and referenced?

Variable name = variable Content # content can be path, command, string, number, etc.

Variable reference $ variable name # such as Cheng=30

# echo $cheng #结果就是30

4) Special variables (the system has pre-defined characters that represent fixed content)

The name of the shell script

$n the nth parameter of a shell script

$* [email protected] All the parameters of the shell script (slightly different from the data analysis can be checked)

$# the number of arguments to the shell script

Special variables that are not commonly used

$! The process number of the last script running in the background

$$ the process number of the script

$? The return value of the previous command or script in the shell script (what is the return value? can be used as a non-existent, only when the wrong time)

$_ the last parameter of the script

5) The substring of the variable (sometimes we need to get a part of the variable, at which time the variable quantum string is the fastest way to calculate)

Such as

Cheng=ruofei

echo ${#cheng} #计算变量的字符个数

6

Echo ${cheng:2} #显示第2个字符以后的字符

Eng

6) Calculation of variables

When the content of a variable is a number, it involves the numerical calculation of the variable, which we use (()) to automatically calculate

Such as

Cheng=30

Zhang=cheng+1

Echo $zhang

Cheng+1

Zhang= ((cheng+1))

Echo $zhang

31

Linux self-Study _shell variable Chapter

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.