Shell Getting Started-variables

Source: Internet
Author: User

Shell variables are divided into system variables and user-defined variables

commands to view variables

#env System Variables

Or #set include env and custom variables and extra variables

The command to use the variable is

#echo $ "Variable"

/////////////////////////////////////////////////////////////////////////////

1. Custom variables

It is recommended to use lowercase to differentiate system variables.

[Email protected] 111]# a=1
[Email protected] 111]# echo $a
1

[Email protected] 111]# a=1;b=2;c=3
[Email protected] 111]# echo $a $b $c
1 2 3
[Email protected] 111]# echo $a $b$c
123

2. Single quotes for variables of special characters

[Email protected] 111]# a= ' ... +++--**//'
[Email protected] 111]# echo $a
...+++--**//

3. Using the command to run the result with the inverted quotation mark

[Email protected] 111]# a= ' ll 1.txt '
[Email protected] 111]# echo $a
-rw-r--r--1 root root 4 November 22:03 1.txt

=

4. Let the variable overlay with double quotation marks

[Email protected] 111]# a=1
[Email protected] 111]# b= "$a" 2
[Email protected] 111]# echo $b
12

////////////////////////////////////////////////////////////////////////////////////////////

Global Declaration

Command: Export

Description: Global declaration

[Email protected] 111]# d=5
[Email protected] 111]# echo $d
5
[[email protected] 111]# bash////enters child shell variable a fails

[Email protected] 111]# echo $d

[[Email protected] 111]# exit//exit child shell
Exit
[[email protected] 111]# export d=6//Global declaration
[Email protected] 111]# echo $d
6
[[email protected] 111]# Bash//Enter child shell
[Email protected] 111]# echo $d
6

/////////////////////////////////////////////////////////////////////////////////////////////////////////

Summary: A=1, echo $a//a=1;b=2;c=3 echo $a $b$c//a= ' + +. --'//a= ' cat 1.txt '//a= "$b" 1//Export a=1, bash, echo $a//

Shell Getting Started-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.