shell 讀取文本並訪問mysql
阿新 • • 發佈:2018-08-08
div nbsp lec pro .... strong echo stat code
#!/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 ......)
shell 讀取文本並訪問mysql