shell中常用的算术运算
1.使用 expr 外部程式
x=4
y=5
r=`expr $x + $y + 1`
r=$((x+y+1))
r=$(($x+$y+1))
r=$[x+y+1]
r=$[$x+$y+1]
let r=x+y+1
let "r=$x+$y+1"
let r=$x+$y+1
echo $x + $y + 1 | bc
echo "$x + $y + 1" | bc
r=`echo $x $y | awk '{print $1+$2}'`
下面shell脚本实现的功能:
- 连续执行sql语句
- 不打屏(2>&1)
- 定时生成一个日志(防止日志文件过大)
- 每个循环添加一个时间戳
- 文字闪烁效果的应用
db=postgres
port=6000
num=1
echo -e "\033[37;31;5mI am running,don't touch me!!!!!!!!\033[39;49;0m"
echo "clean test1" > test1
for ((i=1;i<=51840;i++));do
{
echo $(date +%F%n%T) >> test$num
gsql -d $db -p $port -a -f "mysql_create_alter_table_function_scence.sql" >> test$num 2>&1 &
wait
gsql -d $db -p $port -a -f "mysql_create_alter_table_abnormal_scence.sql" >> test$num 2>&1 &
wait
if [ $(($i%1000)) == 0 ];then
num=$(($num+1))
fi
}
done