PASH LOOP DONZIP Passificed файл скрипта

Вам, вероятно, все равно придется перезапустить этот интерфейс, чтобы изменения вступили в силу. ifup eth0 сделает свое дело.

6
08.08.2018, 16:27
2 ответа

Если у вас нет и вы не можете установить zipinfoпо какой-либо причине, вы можете имитировать его, используя unzipс опцией -Z. Чтобы просмотреть содержимое zip, используйтеunzip -Z1:

pw="$(unzip -Z1 file1.zip | cut -f1 -d'.')" 
unzip -P "$pw" file1.zip

Поместите его в петлю:

zipfile="file1.zip"
while unzip -Z1 "$zipfile" | head -n1 | grep "\.zip$"; do
    next_zipfile="$(unzip -Z1 "$zipfile" | head -n1)"
    unzip -P "${next_zipfile%.*}" "$zipfile"
    zipfile="$next_zipfile"
done

или рекурсивная функция:

unzip_all() {
    zipfile="$1"
    next_zipfile="$(unzip -Z1 "$zipfile" | head -n1)"
    if echo "$next_zipfile" | grep "\.zip$"; then
        unzip -P "${next_zipfile%%.*}" "$zipfile"
        unzip_all "$next_zipfile"
    fi
}
unzip_all "file1.zip"

-Z zipinfo(1) mode. If the first option on the command line is -Z, the remaining options are taken to be zipinfo(1) options. See the appropriate manual page for a description of these options.

-1 : list filenames only, one per line. This option excludes all others; headers, trailers and zipfile comments are never printed. It is intended for use in Unix shell scripts.

8
27.01.2020, 20:21

Спросите уzipinfoимя файла, указанное в zip-архиве, затем запишите его для пароля. Используйте этот пароль для распаковки файла:

pw=$(zipinfo -1 file1.zip | cut -d. -f1)
unzip -P "$pw" file1.zip

Обратите внимание, что флаг для zipinfoявляется единицей , а не ell .

Заимствуя из ответа Жиля на аналогичный вопрос , вот цикл bash, который будет извлекать вложенный zip-файл, -защищенный паролем, до тех пор, пока не останется zip-файлов:

shopt -s nullglob
while set -- *.zip; [ $# -eq 1 ]
do 
  unzippw "$1" && rm -- "$1"
done

Где я определил функцию unzippwкак оболочку для команд zipinfoи unzipвыше:

unzippw ()
{
    local pw=$(zipinfo -1 "$1" | cut -d. -f1)
    unzip -P "$pw" "$1"
}
8
27.01.2020, 20:21

Теги

Похожие вопросы