Shell Script (vii)
J, Array
#关联数组: A generic array index must be a numeric value, and an associative array index can be a string
#也可以是数值, similar to a Python dictionary
awk ' BEGIN {str[name]= ' string '; str[1]= "1"};p rintf ("%s\n%s\n", str[name],str[1])}650; "this.width=650"/HTTP// S3.51cto.com/wyfs02/m01/6e/43/wkiol1v35uehnj1waaa90val3ge089.jpg "/>
#split函数, note that the for (I-in name) output is random
Awk-f: ' {split ($0,name, ': '); for (I-in name) print I, ":", Name[i]} ' num.txt
Awk-f: ' {split ($0,name, ":"); for (i=1;i<=nf;i++) print I, ":", Name[i]} ' num.txt
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/47/wKiom1V346KyAbQbAADQmw2eHtQ792.jpg "/>
#数组形式的系统变量, Enviro storage is a system environment variable
awk ' BEGIN {for (i in ENVIRON) print i "=" environ[i]} '
5. Variables and references
(1) Variables
A, variable substitution and assignment
Symbols such as #变量名只能包含大小写字母, numbers, draw lines, etc., and cannot start with a number
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/43/wKioL1V35Uiyd0FfAAEMiYRXdlg310.jpg "/>
#变量赋值
Var=value: Assigning value values to Var
Var+value: Reset the value of the assigned Var
Var?value or Var:?value: Displays system error messages for unassigned Var
Var:=value: Assigns value to an unassigned Var
Var:-value: Assigns value to an unassigned Var, but value does not store the address space corresponding to Var
Echo ${name:-carl}
Echo ${name:=carl}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/47/wKiom1V346OCcG1tAACOhVZopG4175.jpg "/>
Echo ${var?test}
Echo ${var:?test}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/43/wKioL1V35UjQLczjAABn9thR5e0014.jpg "/>
#设置只读变量
ReadOnly rdonly
B, untyped shell script variables
#shell的变量是无类型的, floating-point type not supported, only shaping and character type supported
#字符型变量有一个默认整型值0, the character variable is empty by default, and the string is assigned to the integer type directly
#变量, the integer variable becomes a character variable, and the character variable is increased by 1, and the variable becomes
#整型, and the value is 0
Name= "Test"
Num= "123"
#将字符变量name强制转换成整型, the value is also "test"
#转换后直接当数值使用, the default value is =0
Declare-i Name
Echo $name
#将字符型变量自增1, it becomes an integral type. If the variable value is all numbers, it is used as an integral type
Let name++
Echo $name
Let name++
Echo $name
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/47/wKiom1V346OQwXNQAADCHxDlHNY486.jpg "/>
c, Environment variables
#定义和清除环境变量, environment variables generally use uppercase letters
Myls=/bin/ls
Export Myls
Echo $MYLS
$MYLS
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/43/wKioL1V35UmQcktfAAC8cXBLb_4813.jpg "/>
#清除环境变量, the value of the variable becomes empty by default
unset Myls
Echo $MYLS
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/47/wKiom1V346Syd_aSAAA2c5Dm-uk988.jpg "/>
#常用环境变量
PWD: Current Working directory
OLDPWD: Last working directory
Path: Indicates the path to the executable file
HOME: The root directory of the current user
SHELL: Default is/bin/bash
User: Login username
UID: Login User ID
PPID: Creates the process number of the current process, which is the parent process number of the current process
PS1: Prompt variable to set the first-level shell prompt format, default to "[\[email protected]\h \w]\$"
PS2: Prompt variable, used to set level two shell prompt format, default to ">", enter the incomplete command will be displayed
\u: Indicates the current user name
\@: Indicates time is displayed in 12-hour system
\h: Indicates host name
\w: Indicates the current working directory name
\w: Represents the full name of the current working directory
\$: If the UID is 0, print "#"; otherwise, print "$"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/43/wKioL1V35UnwPNSRAADPy1WZ_wE319.jpg "/>
#IFS: Shell field delimiter, default to space, to ":", space separated by field from field
Export ifs=:
Echo $PATH
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/47/wKiom1V346Tg_8uTAABN40ZxlSQ536.jpg "/>
#环境变量配置文件:. Bash_profile,. BASHRC,. Bash_profile and/etc/profile
#前3个全部以隐藏形式存放到 $HOME/down, for the corresponding user, and finally for the global settings
d, Position parameters
(2) References
A, full reference and partial references
B, Command substitution
C, Escape
6. Exit, test, judgment and operator
(1)
7. Advanced usage of Variables
8. I/O redirection
9. Child shell and process processing
10. Functions
11. Aliases, lists, and arrays
12. Script Debugging
13. Shell Combat
This article is from the "Love On Action" blog, please be sure to keep this source http://1055745601.blog.51cto.com/5003160/1660425
Shell Script (vii)