Shell environment variables + special variables (definition of arrays and additions, deletions, and changes)

Shell variable types: (divided into two categories)
environment variables (global variables) and local variables
#######General environment variables are all uppercase #########

There are no quotation marks for the three symbols of variables
: generally continuous strings, numbers, paths, etc. can be without any quotation marks
'single quotation marks': what you see is what you get, what you see will be output
"double quotation marks": put double quotation marks All content inside is output; if the content contains commands (to be used 反引号), variables, special translation characters, etc.

**** shell special variables $#* **
Position variables: (add double quotes)
$* Get all the parameters of the current shell, treat all command line parameters as delay strings
$# Get the current shell script after the execution Total number of parameters
$@ Get all parameters of this program "$1" "$2" "$3"


**** Add, delete, modify and check array definition* ****
1. Array definition:
[root@localhost ~]# text=(1 2 3 4 5)br/>2. Length of array:
### You can use @ or * in [] to get ###
[root@localhost ~]# echo ${#text[@]}
5
[root@localhost ~]# echo ${#text[*]}
5
3. Print Array elements:
start from 0, 0 represents the first element
[root@localhost ~]# echo ${text[0]}
1
[root@localhost ~]# echo ${text[1]}
2
[root@localhost ~]# echo ${text[2]}
3
[root@localhost ~]# echo ${text[3]}
4
[root@localhost ~]# echo ${text[4]}
5

[root@localhost ~]# set -- "I am" shuyun yunwei.
[root@localhost ~]# for i in "$*";do echo $i;done
I am shuyun yunwei.
[root@localhost ~]# for i in "$#";do echo $i;done
3
[root@localhost ~]# for i in "$@";do echo $i;done
I am
shuyun
yunwei.

**打印各个参数信息*****
[root@localhost ~]# for i in "$1";do echo $i;done
I am
[root@localhost ~]# for i in "$2";do echo $i;done
shuyun
[root@localhost ~]# for i in "$3";do echo $i;done
yunwei.

****不加双引号**
[root@localhost ~]# for i in $*;do echo $i;done
I
am
shuyun
yunwei.
[root@localhost ~]# for i in $#;do echo $i;done
3
[root@localhost ~]# for i in $@;do echo $i;done
I
am
shuyun
yunwei.
[root@localhost ~]#

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324791740&siteId=291194637