linux – Bash循环解压缩passworded文件脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – Bash循环解压缩passworded文件脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1570字,纯文字阅读大概需要3分钟。
内容图文
![linux – Bash循环解压缩passworded文件脚本](/upload/InfoBanner/zyjiaocheng/959/e1e470944097433fa63dfedbd48280cd.jpg)
我正在尝试创建一个解压密码保护文件的脚本,密码是解压缩时我将获得的文件的名称
例如.
file1.zip contains file2.zip and it's password is file2.
file2.zip contains file3.zip and it's password is file3
如何解压缩file1.zip,并读取file2.zip的名称,以便在脚本中输入?
Here’s a screenshot of what I meant,我只需要bash来读取该输出以便知道新密码
(在这种情况下,密码是13811).
这是我到目前为止所做的
#!/bin/bash
echo First zip name:
read firstfile
pw=$(zipinfo -1 $firstfile | cut -d. -f1)
nextfile=$(zipinfo -1 $firstfile)
unzip -P $pw $firstfile
rm $firstfile
nextfile=$firstfile
现在我该如何让它循环?
解决方法:
如果您因任何原因没有也无法安装zipinfo,可以使用-Z选项解压缩来模仿它.要列出zip的内容,请使用unzip -Z1:
pw="$(unzip -Z1 file1.zip | cut -f1 -d'.')"
unzip -P "$pw" file1.zip
把它放到一个循环中:
zipfile="file1.zip"
while unzip -Z1 "$zipfile" | head -n1 | grep "\.zip$"; do
next_zipfile="$(unzip -Z1 "$zipfile" | head -n1)"
unzip -P "${next_zipfile%.*}" "$zipfile"
zipfile="$next_zipfile"
done
或递归函数:
unzip_all() {
zipfile="$1"
next_zipfile="$(unzip -Z1 "$zipfile" | head -n1)"
if echo "$next_zipfile" | grep "\.zip$"; then
unzip -P "${next_zipfile%%.*}" "$zipfile"
unzip_all "$next_zipfile"
fi
}
unzip_all "file1.zip"
-Z zipinfo(1) mode. If the first option on the command line is -Z, the remaining options are taken to be zipinfo(1) options. See the appropriate manual page for a description of these options.
-1 : list filenames only, one per line. This option excludes all others; headers, trailers and zipfile comments are never printed. It is intended for use in Unix shell scripts.
内容总结
以上是互联网集市为您收集整理的linux – Bash循环解压缩passworded文件脚本全部内容,希望文章能够帮你解决linux – Bash循环解压缩passworded文件脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。