Wiktor Zielonka
Wiktor Zielonka

Reputation: 11

Unzip 7z archive with password using bash script

I want to unzip a folder with multiple *.7z archives, all with same password.

Unfortunately, using this:

    #!/bin/bash
    password="12345678"
    cd /server/disc/folders.../folderWithArchives
    for package in ./*.7z;
    do
    7z -x -P{$password} $package
    done

gives me

Error: Incorrect command line

Have you any ideas how to fix it?


I've tried shellcheck and it gave me this:

#!/bin/bash
password="12345678"
cd /server/disc/folders.../folderWithArchives || exit
for package in ./*.7z;
do
7z -x -P$password "$package"
done

but it still doesn't work


OS: Ubuntu 16.04.6 LTS

shell: GNU bash, version 4.3.48

Upvotes: 0

Views: 2677

Answers (1)

Wiktor Zielonka
Wiktor Zielonka

Reputation: 11

I found a solution. Everything works OK after only deleting '-' before 'x'. Now it works and looks like this:

#!/bin/bash
password="12345678"
cd /server/disc/folders.../folderWithArchives || exit
for package in ./*.7z;
do
7z x -P$password "$package"
done

Upvotes: 1

Related Questions