Shell variable type: (Divided into two categories)
Environment variables (global variables) and local variables
###### #一般环境变量都为大写 #########
Three symbols of the variable
No quotation marks: usually consecutive strings, numbers, paths, etc. can be without any quotation marks
' Single quote ': What you see is what you get, what you're going to be exporting.
"Double quotes": The output of everything inside the double quotation marks, if there are commands (to be used 反引号
), variables, special translators, etc.
* * *Shell special variable $#** *
Positional variables: (plus double quotes)
$* 获取当前shell的所有参数,将所有的命令行参数视为耽搁字符串$# 获取当前执行的shell脚本后的参数总个数[email protected] 获取这个程序的所有参数“$1" "$2" "$3"
* * * * * * * * for array definition
1.数组的定义:[[email protected] ~]# text=(1 2 3 4 5)2.数组的长度获取:###【】里可以用@或者*来获取###[[email protected] ~]# echo ${#text[@]} 5[[email protected] ~]# echo ${#text[*]} 53.打印数组元素:从0开始取,0代表第一个元素[[email protected] ~]# echo ${text[0]} 1[[email protected] ~]# echo ${text[1]} 2[[email protected] ~]# echo ${text[2]} 3[[email protected] ~]# echo ${text[3]} 4[[email protected] ~]# echo ${text[4]} 5[[email protected] ~]# set -- "I am" shuyun yunwei.[[email protected] ~]# for i in "$*";do echo $i;doneI am shuyun yunwei.[[email protected] ~]# for i in "$#";do echo $i;done 3[[email protected] ~]# for i in "[email protected]";do echo $i;done I amshuyunyunwei.
* * Print individual parameter information * * * * * * *
[[email protected] ~]# for i in "$1";do echo $i;doneI am[[email protected] ~]# for i in "$2";do echo $i;done shuyun[[email protected] ~]# for i in "$3";do echo $i;done yunwei.
* * * without double quotes * *
Shell environment variables + special variables (definition of arrays and additions and deletions)