A 1.shell programming language is a dynamic language (a weakly typed language) that interprets side execution at run time, does not need to be declared before it is used, is declared in use, and does not even differentiate between variable types, but is a process-oriented language.
2. Variables: variables are named memory space, Memory: Memory is the address of the storage unit.
3. Type of variable: pre-determined data storage format and length
字符型:如a ‘abc’ ‘123’等 数值型: 整型:如1,123等 浮点型:如,3.14等 bool类型:表示真、假类型
4. Logical operators: With, or, non-, XOR, or
如:用1:真,0:假,&:与,|:或,!:非,^:异或 在与运算中,全为真结果才为真: 1 & 1 = 1 1 & 0 = 0 0 & 1 = 1 0 & 0 =0 或运算中,只要有一个为真,结果就为真,如: 1 & 1 = 1 1 & 0 = 1 0 & 1 = 1 0 & 0 = 0 非运算中,真为假,假为真,如: !真 = 假 !假 = 真 异或运算中,只有相同的状态才为假,如 1^1 = 0 1^0 = 1 0^1 = 1 0^0 = 0
5. Variable assignment: var_name=value (= no spaces on both sides)
Variable type of 6.bash
环境变量:作用域为当前shell以及其子shell(命令bash进入子shell,exit退出) 可以使用export VAR_NAME=VALUE或者VAR_NAME=VALUE,export VAR_NAME来设置环境变量 本地变量:作用整个shell进程 可以使用 VAR_NAME=VALUE或set VAR_NAME=VALUE设置 局部变量:只作用于当前代码段 使用 local VAR_NAME=VALUE 特殊变量: 如:$? 返回上一条命令的执行结果,0表示执行成功,1-255表示失败,可以使用echo $? 查看 位置变量: 如:$1,$2,$3等 查看当前shell中的变量可以使用set、printenv、export查看 撤销变量unset VAR_NAME可以撤销VAR_NAME的变量设置。
7. Script Format:
shell脚本的命令以 .sh作为后缀,首行必须为 #!/bin/bash或#!/bin/sh用来作为编译器。 #:用来注释,后面的代码不会执行。
8. Script run:
可以使用sh xxx.sh执行xxx.sh脚本,或者赋予xxx.sh脚本执行权限,然后使用 路径/xxx.sh执行,如果要直接xxx.sh不加路径执行,需要在PATH变量里添加xxx.sh的路径。
Shell Change Programming One