Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can capture args with xargs across multiple pipe in bash

I have this command

kubectl get ns -l app=sample-api | awk '/fast/{print $1}' |
xargs -I {} helm list --short -n {} | xargs -I {} helm delete -n ?? {}

Suppose that argument from first xargs is $1 and it gets subsituted in like helm list --short -n {$1}

and $2 is the argument of second Xargs and its gets substituted like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

helm delete -n ?? {$2}

but i also want $1 to use like this in last comand

helm delete -n {$1} {$2}

is this possible ?

output of first xargs

name1
name2
name3

second xargs

chart1
chart2
chart3

>Solution :

I would simply break it up into a separate loop.

kubectl get ns -l app=sample-api |
awk '/fast/{print $1}' |
while read -r name; do
    target=$(helm list --short -n "$name")
    helm delete -n "$name" "$target"
done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading