简体   繁体   中英

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. I didn't originally write this and have no experience writing bash scripts so I have no idea what to try

#/bin/sh
for file in *.zip
do
unzip -P pcp9100 "$file" -d ../ 
done

Remove "-d" option. 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:

#/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 ; do unzip $file -d echo $file | cut -d . -f 1 echo $file | cut -d . -f 1 echo $file | cut -d . -f 1 ; done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM