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})
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}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.