我想要一个shell脚本(ubuntu),它逐行从sql表中获取数据! 我希望能够访问 EACH 行,例如用一个简单的if语句检查,你知道吗?
#!/bin/bash
TIME=`date +"%T"`
echo true > log/ausgefuehrt-$TIME.log
/opt/lampp/lampp start
echo $TIME
#ASSIGNING MYSQL
MYSQL=/opt/lampp/bin/mysql
#$MYSQL -e"select * from ftp.ftp" -u root
$MYSQL -e"select * from ftp.ftp"
#STARTING TO FETCH EACH ROW (trying)
WHILE read ROW ;
do echo $ROW # HERE <<< is the problem.. i dont know how to access each row :/
done
exit
答案 0 :(得分:7)
通过while循环管道mysql
的输出,如下所示:
$MYSQL -e"select * from ftp.ftp" | while IFS= read -r ROW
do
echo "$ROW"
done