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}