shell错误一例 syntax error: unexpected end of file

昨天写个脚本,用shell读取文本文件,并且在循环中使用读取的信息。

循环很正常,获取,展示也很正常,只是在加上mysql xxxx (好几行)的时候,报错“syntax error: unexpected end of file”。

 

后来才想起,是因为mysql命令多行造成的。改成一行输入,就OK了。

 

现在用的如下:

#!/bin/sh

mysql_list_file='mysql_db_list.txt'

if [ -f $mysql_list_file ]
then
  while read line
  do
    if [ -n "$line" ]
    then
      echo "$line"
      DB_UNAME=`echo "$line" | awk '{print $1}'`
      DB_UPASS=`echo "$line" | awk '{print $2}'`
      DB_IP=`echo "$line" | awk '{print $3}'`
      DB_DBNAME=`echo "$line" | awk '{print $4}'`
      echo ==
     
      mysql -s -u$DB_UNAME -p$DB_UPASS -h $DB_IP -e " \
      use $DB_DBNAME;                                 \
      select count(1) from AAAA;                      \
      exit                                            \
      "
           
    fi
  done < $mysql_list_file
fi

 

你可能感兴趣的:(shell错误一例 syntax error: unexpected end of file)