In reference to this question I still struggle the following single-liner to work
kubectl get ns | while read -r line; do echo `$line | grep Term | cut -d' ' -f1`; done
I would expect to print out the result of $line | grep Term | cut -d' ' -f1
however it prints out an empty line (echo
) and then executes the result of $line | grep Term | cut -d' ' -f1
bash: NAME: command not found
bash: cert-manager: command not found
bash: configmap-4262: command not found
bash: configmap-4430: command not found
Same results with a slightly different approach:
kubectl get ns | while read -r line; do ns=`$line | grep Term | cut -d' ' -f1`; echo $ns; done
What I actually want to achieve is to use the result of $line | grep Term | cut -d'
as an input of a shell script e.g.
do ns=`$line | grep Term | cut -d' ' -f1`; ./delete-kube-ns.sh $ns;
or
$line | grep Term | cut -d' ' -f1` | xargs ./delete-kube-ns.sh