首页 > 解决方案 > 如何修复仅返回 0

问题描述

我有这个 bash 脚本,我想在 mysql 中搜索 list.txt 中的所有内容

如果找不到,我想将其写入 newout.txt 文件。

一切都在 list.txt 中相互写入

#!/bin/bash
file="/tmp/list.txt"


while IFS= read -r line
do
FIELDVALUE=$(mysql databse -u user-ppw -e "SELECT count(name) FROM db WHERE name LIKE '$line';")
count=$(echo $FIELDVALUE |awk '{print $2}')

if [ $count -gt 0 ]
then
 echo "greater that 0 "
else
 echo "$line" >> /tmp/newout.txt
fi

done <"$file"

我总是回到 0 虽然它肯定在那里

: 0 低于 0 0 低于 0

标签: mysqlbash

解决方案


推荐阅读