[英]linux bash script unzip to same directory
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.我有这个 bash 脚本,可以解压缩一堆受密码保护的文件,但它解压缩到我的主目录,而不是我需要它的 zip 文件所在的同一文件夹。 I didn't originally write this and have no experience writing bash scripts so I have no idea what to try
我最初没有写这个,也没有编写 bash 脚本的经验,所以我不知道该尝试什么
#/bin/sh
for file in *.zip
do
unzip -P pcp9100 "$file" -d ../
done
Remove "-d" option.删除“-d”选项。 You script basically providing it a path of "../" which is your main directory.
你的脚本基本上为它提供了一个“../”的路径,这是你的主目录。 Use the below script
使用下面的脚本
#/bin/sh for file in *.zip do unzip -P pcp9100 "$file" done
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
This one liner also works like a charm, a variation on the answers above这个衬里也像魅力一样,是上述答案的变体
$ for file in ls *.zip
; $ 用于
ls *.zip
; do unzip $file -d echo $file | cut -d . -f 1
解压 $file -d
echo $file | cut -d . -f 1
echo $file | cut -d . -f 1
echo $file | cut -d . -f 1
; echo $file | cut -d . -f 1
; done完毕
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.