shell 读取文本并访问mysql

#!/bin/bash
File="redeemcode.csv"
#File=$1

database="d_redeem_info"

echo "check redeemcode state begin..."

while read line
do
if [ -z "$line" ];then
 echo "is null"
else
 #rlt=`mysql -D $database -h127.0.0.1 -uroot -proot -e "select * from  t_redeem_code where c_redeem_code = '${line}';" `
 rlt=$(mysql -D $database -h127.0.0.1 -uroot -proot -e "select * from  t_redeem_code where c_redeem_code = '${line}';" )
fi

done < ${File}

echo "check redeemcode state end..."

shell传参:$0 为执行的文件名,$n,n代表第几个参数

读文件:

while read line
do
  echo $line
done < ${File}

逻辑判断:

if [ -z "$line" ];then
 echo "is null"
else
 echo "not null"
fi

接收mysql操作返回值:

rlt='mysql -h ......'
rlt=$(mysql -h ......)

猜你喜欢

转载自www.cnblogs.com/faithfu/p/9442023.html
今日推荐