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

前端 未结 4 1598
面向向阳花
面向向阳花 2021-02-04 06:13

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

相关标签:
4条回答
  • 2021-02-04 07:09

    Try using

    unzip -o
    

    in your loop

    0 讨论(0)
  • 2021-02-04 07:12
    for f in *zip
    do
       echo "yes" | unzip $f
    done
    
    0 讨论(0)
  • 2021-02-04 07:17

    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
    
    0 讨论(0)
  • 2021-02-04 07:18
    unzip -o $f
    

    per the docs

    0 讨论(0)
提交回复
热议问题