Created 星期三 03 四月 2019
在第一行添加
sed -i '1i\#!/bin/bash' *.sh
删除第一行
sed -i '1d' *.sh
获取最后一行
1.awk 'END {print}'
2.sed -n '$p'
3.sed '$!N;$!D'
4.awk '{b=a"\n"$0;a=$0}END{print b}'
颜色输出
function func_write_log()
{
var_str=$1
var_color=$2
var_curr_timestamp=`date "+%Y-%m-%d %H:%M:%S"`
## 判断参数1 是否是空字符串
if [ "x${var_str}" == "x" ];then
var_str=""
else
var_str="${var_curr_timestamp} ${var_str}"
fi
## 判断颜色
if [ "${var_color}" == "green" ];then
var_str="\n\033[32m${var_str}\033[0m"
elif [ "${var_color}" == "yellow" ];then
var_str="\033[33m${var_str}\033[0m"
elif [ "${var_color}" == "red" ];then
var_str="\033[1;41;33m${var_str}\033[0m"
else
var_str="\033[37m${var_str}\033[0m"
fi
## 打印输出
echo -e "${var_str}"
#echo -e "${var_str}" >> ${var_path}/test_${var_curr_timestamp}.log 2>&1 #写入日志文件
}
find ~ -name ‘*.log’ -print0 | xargs -0 rm -f
for 循环的几种方式
#!/bin/bash
#basic for command
for test in Alabama BOb Tom Console
do
done
#!/bin/bash
#basic for command
for test in Alabama BOb Tom Console
do
echo The next state is $test
done
#!/bin/bash
#使用类C风格for循环输出1~5
for ((integer = 1; integer <= 5; integer++))
do
echo "$integer"
done
#!/bin/bash
for i in $(seq 1 10)
do
echo $(expr $i \* 3 + 1);
done