Bash 脚本 - Find & While 循环不起作用

Bash 脚本 - Find & While 循环不起作用

我有这个 bash 脚本,但它似乎在“查找”点不起作用。

#!/bin/bash
echo 'What date YYYY-MM-DD format?'

read date

echo "starting restore script..."
echo "Looking in /root/backups/dbback_$date/"

cd "/root/backups/dbback_$date/"

echo 'What search term for files?'

read search

echo 'What database am I restoring too?'

read database

count=`ls -l | grep "$search" | wc -l`
echo "$count files found containing $search"

find "/root/backups/dbback_$date/" -type f -name '$search*.sql.gz' -not -path '*livefiles*' | while read file; do
echo "$file is being restored"
gunzip < "$file" | mysql -u root -p* '$database';
echo "$file has been restored...moving on to next file."
done

在找到和完成之间 - 没有发生任何事情,我得到的最后一个回声是

找到 9 个包含测试的文件

如果我做错了什么,有人可以建议吗?

答案1

find "/root/backups/dbback_$date/" -type f -name "${search}*.sql.gz" -not -path '*livefiles*' | while IFS= read -r file; do
echo "${file} is being restored"
gunzip < "${file}" | mysql -u root -p* $database;
echo "${file} has been restored...moving on to next file."
done

现在有效

相关内容