sid_com
sid_com

Reputation: 25157

Perl-oneliner to bash

perl -E '$i=@{[`zypper lr`]}-2;map{`zypper rr $_`}1..$i'

What would be a good way to write this perl-onliner in bash. ( I would like to remove all repositores with zypper)?

Upvotes: 0

Views: 336

Answers (2)

daxim
daxim

Reputation: 39158

zypper lr | grep -P "^\d" | cut -d'|' -f 1 | xargs sudo zypper rr

But much easier to simply:

sudo rm -rf /etc/zypp/repos.d/*

Upvotes: 0

DVK
DVK

Reputation: 129569

Here's a way to do this:

The first command counts the number of lines produced by zypper lr command.

So, you obtain that by:

COUNT_LINES=`zypper lr|tail +3|wc -l`

The second command merely runs zypper rr [NUMBER] for each number 1 through the counter; so you run the for loop in bash as shown in this SO question:

How do I iterate over a range of numbers in bash?

Upvotes: 1

Related Questions