对于我的学校项目,我必须创建一个脚本,允许您搜索 zip 文件中打包的文件的内容。您可以在脚本中指定一个“搜索字符串”,后跟一个或多个 zip 文件,如下所示:
./searchZip.sh -s Tom ztest1.zip ztest2.zip
Found the word 'Tom' in the following files:
ztest1.zip : script1_q0638730_04-18-23-04-41.txt
ztest2.zip : script2_q0638730-04-25-19-52-07.txt
Run Code Online (Sandbox Code Playgroud)
我尝试了,但我不知道如何给出第二个参数,有人可以帮助我吗?谢谢你!这是我的代码:
function unzipFile()
{
unzip ztest1.zip -d zipFiles
unzip ztest2.zip -d zipFiles
unzip ztest3.zip -d zipFiles
}
if test -z "$1"
then
echo "Enter a name please "
exit
else
unzipFile
echo "Found the word '$1' in the following files:"
grep -ilR "$1" zipFiles/
fi
rm -r zipFiles/
Run Code Online (Sandbox Code Playgroud)