1、shell 脚本第一行 #!后面的!来告诉shell用哪个shell来运行脚本,可以使用base shell
2、环境变量:$ 符号
3、用户变量 : 区分大小写
group=mysql user=mysql
1、cat << EOF > /etc/my.cnf
EOF 结束符可将指定内容输入到指定的文件中 cat << EOF > /etc/my.cnf [mysqld] port=3306 !includedir /etc/my.cnf.d EOF2、命令替代
可以将命令输出赋值给变量 反引号(``)和$() password=`cat $basedir/initinfo | grep password | awk -F " " {'print $NF'}`3、if else-if else
if else-if else if else-if else 语法格式: if condition1 then command1 elif condition2 then command2 else commandN fi4、文件比较
1、检测目标 -d检测目录是否存在 2、检测对象 -e比较文件和目录是否存在 3、检测文件 -e比较可用于文件目录。确定指定对象为文件,必须用 -f 比较 #!/bin/bash item_name=$HOME if [-e $item_name] then ..... if[-e $item_name] then...5、使用双括号
(()) [[]] ()里面的特殊字符可以不用转义 []: 提供了模式匹配 if[[$SURE == r*]] 是否已r 开头