tags:

views:

174

answers:

3

Hi all,

I wrote a loop to unzip all zip files in a directory.

for f in *zip
do
    unzip $f
done

However, I have to confirm the overwrite at every step:

replace file123.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A

How can I rewrite a loop to send at every cycle the same command?

+3  A: 
unzip -o $f

per the docs

Jonathan Feinberg
+6  A: 

Wonderful, maybe one of the few cases where yes is still useful

Try with:

for f in *zip
do
    yes | unzip $f
done

Which will work printing "y" at every command.

Or alternatively, you can specify the string provided by yes, like:

for f in *zip
do
    yes A | unzip $f
done
Thrawn
<yes> can provide also a "never overwrite" capability, which seems to lack among the unzip options
Thrawn
+2  A: 

Try using

unzip -o

in your loop

Alberto Zaccagni