I am running the following command in a bash script:
kubectl get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep 'myservice'
but for some reason, it is not returning anything at all. If I run the command in the terminal it returns the expected result, but for some reason, running it in my bash script does not work. Here is my snippet (note, SERVICE is passed in, and verified by echo
ing it.
echo $(kubectl get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep '${SERVICE}')
if [[ $(kubectl get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep '${SERVICE}' | wc -l) -eq "0" ]]; then
echo "ERROR Service [${SERVICE}] does not exist."
exit
fi
Running this with a valid service name returns:
$ ./script.sh -s myservice
ERROR Service [myservice] does not exist.
I've tried using backticks, wrapping the $(...)
in double-quotes, but it will not execute, so there must be something in the --template
section that its not liking. Could someone help me identify what that is please?
EDIT, the linked question does not answer this one, it does not even include the characters $(
.