1

我对 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循环,但我尝试了几次不同的时间,但无法让它做我想做的事。

4

1 回答 1

2

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

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

filenum=1
...
whois "$dn" > /root/Desktop/$client/Whois/whois$filename.txt
let filename=filenum+1
于 2013-10-31T04:57:05.210 回答