#!/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%?}';" )
cham=`redis-cli -h 192.168.1.6 -p 6380 hset guild_info:${arr[0]} activity_contribution ${arr[1]}` 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
shell去掉最后一个字符:
${line%?}
接收mysql操作返回值:
rlt='mysql -h ......' rlt=$(mysql -h ......)