Home > Enterprise >  How to list k8 namespace in a single line
How to list k8 namespace in a single line

Time:07-21

What I want to do is to output all namespaces in a singleline to a variable so I can delete the namespaces later.

Example:

TOBEDELETED=$(kubectl get namespace -o=name | grep "SOME_NAME")

eval $(kubectl delete namespace ${TOBEDELETED})

CodePudding user response:

An easy way is to pipe the output of your grep to tr "\n" " " to replace all newlines with spaces. Also, your eval is unnecessary.

TOBEDELETED=$(kubectl get namespace -o=name | grep "SOME_NAME" | tr "\n" " ")
kubectl delete namespace ${TOBEDELETED}
  • Related