如何在bash中为每个命令增加日志文件的名称?

如何在bash中为每个命令增加日志文件的名称?,bash,Bash,我对bash脚本相当陌生,但我真的在尽可能多地学习。我写了一个剧本,但有几个不同的问题。1.如果用户回答“y”再次运行脚本,我希望脚本继续运行。2.我还希望脚本输出一个文件,但将文件名增加1。这是我正在使用的脚本: #Whois commands echo "Whois Scan Starting" echo "" echo "Please enter a domain name for a Whois lookup" read dn whois "$dn" > /root/Desktop

我对bash脚本相当陌生,但我真的在尽可能多地学习。我写了一个剧本,但有几个不同的问题。1.如果用户回答“y”再次运行脚本,我希望脚本继续运行。2.我还希望脚本输出一个文件,但将文件名增加1。这是我正在使用的脚本:

#Whois commands
echo "Whois Scan Starting"
echo ""
echo "Please enter a domain name for a Whois lookup"
read dn
whois "$dn" > /root/Desktop/$client/Whois/whois.txt
read -rsp $'All done. Press enter to continue...\n'
read -p "Would you like to do another Whois lookup? [yn]" answer
if [[ $answer = y ]] ; then
#run the command
echo "Please enter a domain name for a Whois lookup"
read dn
whois "$dn" > /root/Desktop/$client/Whois/whois2.txt
read -rsp $'All done. Press enter to continue...\n'
fi

我猜我需要使用while循环,但我尝试了几次不同的方法,但都无法实现我想要的

要继续询问,请使用
while true
循环。当用户回答否时,使用
break
结束循环

对于递增文件名,将变量设置为数字,并在写入每个文件后递增

filenum=1
...
whois "$dn" > /root/Desktop/$client/Whois/whois$filename.txt
let filename=filenum+1