2011-10-09 11 views
7

Chcę zip plik za pomocą powłoki bash, więc użyłem:Jak wyłączyć ostrzeżenie "zip" w bash?

echo -n 'Insert the file path:' 
read path 
echo 'Hello World' > ${path} 
zip -u ${path}.zip ${path} 

Kiedy uruchomić ten skrypt, to daje mi ostrzeżenie:

zip warning: test.zip not found or empty 
adding: test (deflated 66%) 

To działa dobrze, ale jak mogę wyłączyć to ostrzeżenie? Czy używam zip we właściwy sposób?

Odpowiedz

18

Myślę, że chcesz ciche flagi.

zip -uq ${path}.zip ${path} 

Od strony podręcznika:

-q 
--quiet 
      Quiet mode; eliminate informational messages and comment 
      prompts. (Useful, for example, in shell scripts and background 
      tasks). 
+0

+1 To właśnie szukam. Dzięki :) –

1

może można spróbować "add" zamiast Update (-u)?

ze strony człowieka:

add 
      Update existing entries and add new files. If the archive does not exist 
      create it. This is the default mode. 

    update (-u) 
      Update existing entries if newer on the file system and add new files. 
      If the archive does not exist issue warning then create a new archive. 

    freshen (-f) 
      Update existing entries of an archive if newer on the file system. Does 
      not add new files to the archive. 

    delete (-d) 
      Select entries in an existing archive and delete them. 
1

Prawdopodobnie nie powinien powiedzieć zip zaktualizować archiwum (-u). Bez próbnika -u przełącza się próba dodania plików do archiwum i powinna utworzyć nieistniejące archiwa bez ostrzeżeń.

0

Możesz również usunąć zbędne linie wyjściowe i pozostawić normalne informacje o stanie widoczne, ale najpierw musisz przekierować stderr na standardowe wyjście. Na przykład następujące polecenie wyodrębni z wielu plików zip tylko niektóre określone pliki, ale nie wyświetli linii emnpty ani nie będzie narzekać na nie znalezione pliki. W ten sposób masz jeszcze jakieś wyjście logowanie, debugowanie itd

unzip -jn archivedlogfiles\* \*logfile\* 2>&1 | grep -vE '^$|^caution.*' 
Archive: archivedlogfiles1.zip 
    inflating: little_logfile_20160515.log 
    inflating: little_logfile_20160530.log 
Archive: archivedlogfiles2.zip 
Archive: archivedlogfiles3.zip 
Archive: archivedlogfiles4.zip 
Archive: archivedlogfiles5.zip 
Archive: archivedlogfiles6.zip 
Archive: archivedlogfiles7.zip 
Archive: archivedlogfiles8.zip 
    inflating: little_logfile_20160615.log 
    inflating: little_logfile_20160630.log 
Archive: archivedlogfiles9.zip 
2 archives were successfully processed. 
7 archives had fatal errors. 

Zasadniczo nasza komenda będzie wtedy wyglądać tak:

zip -u ${path}.zip ${path} 2>&1 | grep vE '^zip\swarning.*' 
Powiązane problemy