Sekar
Sekar

Reputation: 11

How to avoid skipping incorrect password while unzipping a file in linux?

I am unzipping a password protected zip file using unzip command in linux.

The command will be as follows. unzip -P password datadump.zip

The command skips the incorrect password If the password is incorrect, the command should throw an error, but it is skipping the error.

skipping: FileMaster_data.txt incorrect password

The unzipping did not take place, as well as error is not thrown.

Please help me to avoid the skipping process when an incorrect password is given, for validation purpose.

Thanks in advance.

unzip -P password datadump.zip

I expect to get an exit code error, but it just skips the error.

Upvotes: 1

Views: 1077

Answers (1)

pmqs
pmqs

Reputation: 3735

$? will be zero if unzip worked and non-zero if it failed.

First the use-case that works, where I enter the correct password.

$ unzip -p -P pass  fred.zip 
$ echo $?
0

And this for the failing use-case when I give it an invalid password.

$ unzip -p -P badpassword fred.zip 
$ echo $?
82

Upvotes: 1

Related Questions