#######日期显示
显示当天年月日 date +%Y%m%d
显示明天日期 date -d "+1 day" +%Y%m%d
显示昨天日期 date -d "-1 day" +%Y%m%d
显示上月日期 date -d "-1 month" +%Y%m%d
显示去年日期 date -d "-1 year" +%Y%m%d
双重$($()) $(echo $(date +%Y%y%d))
#############对比
eq等于、ne不等于、gt大于、ge大于等于、lt小于、le小于等于
######参数
$0表示文件名
$1是参数1,依次类推至$9,大于10的时候,要用${10}表示
$#传递脚本的参数个数
$*传递脚本的所有参数
$$传递脚本的PID
$?显示最后命令的退出状态,0表示满意错误,其他任何值表面有错误
$!后台运行的最后一个进程的PID
#######表达式 $(())
格式: $((表达式1,表达式2))
echo $((100*(1+100)/2))
######### read
常用 read -p "please input:" pass #用户输入并将输入的内容复制至pass
#########if
if command;then
commands
elif command;then
commands
else
commands
fi
###########case
case 变量或表达式 in
变量或表达式)
命令序列1;;
变量或表达式)
命令序列2;;
变量或表达式)
命令序列3
case
##########for
#风格A
for var in list;do
commands
done
#风格B
for ((i=0; i<10; i++));do
commands
done
#########while
while 条件;do
命令
done
##########函数
function fun_1 { #定义函数
echo "xxx" #函数的命令集
}
fun_1 #调用函数
exit :整个脚本直接退出,返回数字
return:只是在函数最后一行增加,然后返回数字,只能让函数后面的命令不执行,无法强制退出整个脚本
######sed
sed -i "s/A/B/g" `grep C -rl /etc/*`
#########awk
echo "11:22,33:44" |awk -F"[:|,]" '{print $3}'
echo "11:22,33:44" |awk '{print $(NF-1)}'
awk -F":" '{print $1,"<=====>",$NF}' /etc/passwd