2011-09-13 102 views
0

我想要一個shell腳本(ubuntu),它可以逐行讀取sql表中的數據! 我想訪問EACH行,例如,用簡單的if語句來檢查,你知道嗎?Unix Shell腳本:閱讀和使用MySQL行逐行

#!/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 

回答

6

mysql輸出通過while循環,如下圖所示:

$MYSQL -e"select * from ftp.ftp" | while IFS= read -r ROW 
do 
    echo "$ROW" 
done 
+0

非常感謝你;-) –