Posted on

ZIP

crypted=$( 7z l -slt -- "$file" | grep -i -c "Encrypted = +" )
if [ "$crypted" -ge 1 ]; then
    protected=1
fi

RAR

unrar x -p- -y -o+ "$file" > /dev/null 2>&1
if [ "$?" -eq 3 ]; then
    # exit code 3 means the archive needs a password
    unrar x -p"$password" -y -o+ "$file" > /dev/null 2>&1
fi

Source: https://supportex.net/blog/2011/08/bash-check-zip-rar-file-password-protection/

Table of Contents