Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The not-so-useless "yes" bash command: how to confirm a command in every loop

Tags:

bash

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?

like image 510
Tonio Avatar asked Dec 21 '09 16:12

Tonio


2 Answers

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
like image 149
Federico Giorgi Avatar answered Nov 15 '22 19:11

Federico Giorgi


unzip -o $f

per the docs

like image 22
Jonathan Feinberg Avatar answered Nov 15 '22 19:11

Jonathan Feinberg