Actually I am trying to make the following command in one command
kubectl get pods| grep -oP 'mag[^\s]+'
output
mag121111After that I will run the following command
kubectl exec -itmag121111 bashNow I am trying as following
 kubectl get pods| grep -oP 'mag[^\s]+' | kubectl exec -it bashkubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --/bin/bashOR
kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --bashThis works for me
kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --container magname -- /bin/bashhere magname is actual pod name
kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') -- /bin/bash