Linux batch unzip shell scripts with password rar into the directory with the same file name

Time:2022-5-8

I wrote a batch decompression shell with the password rar, which can be decompressed to a folder with the same file name as RAR. If necessary, please refer to it.

#!/bin/bash
#-----------------------------------
#Batch unzip the RAR with password to the directory with the same file name
#-----------------------------------

#Unzip password
pwd='123456'

for i in *.rar
do
    #Directory name
    dname=$(echo $i|sed 's/.rar//')
    mkdir ./$dname
    #Determine whether the directory was created successfully
    if [ -d "$dname" ]
    then
        Echo - e "directory $dName created successfully \ n" > > ur log
        #Decompression operation
        /usr/bin/unrar x -p$pwd $i ./$dname        
        #Judge whether the decompression is successful
        if [ $? -eq 0 ]
        then
            Echo - e "decompression of $I succeeded \ n" > > ur log
        else
            Echo - e "decompression of $I failed \ n" > > ur log
        fi
    else
        Echo - e "failed to create directory $dnmae \ n" > > ur log
    fi
done

Recommended Today

A front-end developer's Vim is the same as an IDE

Here is my new configurationjaywcjlove/vim-webI've been grinding it, and it's basically ready to use. Take it out and cheat the star Install The latest version of Vim 7.4+ uses (brew install macvim) installation, vim version updatebrew install macvim –override-system-vim View configuration locations # Enter vim and enter the following characters :echo $MYVIMRC download vim-web Download […]