Bash: check if a zip or a rar file has password-protection
ZIP
crypted=$( 7z l -slt -- "$file" | grep -i -c "Encrypted = +" )
if [ "$crypted" -ge 1 ]; then
protected=1
fiRAR
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
fiSource: https://supportex.net/blog/2011/08/bash-check-zip-rar-file-password-protection/