bash linux bash脚本解压到同一目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26392182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
linux bash script unzip to same directory
提问by Katherine Pacheco
hi i have this bash script that unzips a bunch of password protected files, but it unzips to my main directory and not to the same folder the zip files are in which i need it to. I didnt originally write this and have no experience writing bashcripts so I have no idea what to try
嗨,我有这个 bash 脚本,可以解压缩一堆受密码保护的文件,但它解压缩到我的主目录,而不是解压缩到我需要它的 zip 文件所在的同一文件夹。我最初没有写这个,也没有写 bashcripts 的经验,所以我不知道该尝试什么
#/bin/sh
for file in *.zip
do
unzip -P pcp9100 "$file" -d ../
done
thank you for any help
感谢您的任何帮助
采纳答案by dev0z
Remove "-d" option. You script basically providing it a path of "../" which is your main directory. Use the below script
删除“-d”选项。你的脚本基本上为它提供了一个“../”的路径,这是你的主目录。使用下面的脚本
#/bin/sh for file in *.zip do unzip -P pcp9100 "$file" done
#/bin/sh for file in *.zip do unzip -P pcp9100 "$file" done
回答by Katherine Pacheco
I got it now. I still need the -d
option but I removed one dot and it unzipped to the same directory:
我现在明白了。我仍然需要该-d
选项,但我删除了一个点并将其解压缩到同一目录:
#/bin/sh
for file in *.zip
do
unzip -P pcp9100 "$file" -d ./
done
回答by user3019558
This one liner also works like a charm, a variation on the answers above
这个衬里也像魅力一样,是上述答案的变体
$ for file in ls *.zip
; do unzip $file -d echo $file | cut -d . -f 1
; done
$ 用于文件中ls *.zip
;解压 $file -d echo $file | cut -d . -f 1
; 完毕