I would like to take each line of the output of one gcloud command for use in another gcloud command.
gcloud container clusters list |grep jesse
(alias gccl)
output:
jesse-gke1 us-eastx-x
jesse-gke2 us-eastx-x
I need both of these variables (name and region) in the next command.
But when I try to use awk to get the variables I need for the next command, it combines both results into a single variable with 2 lines.
cluster=$(gccl 2>/dev/null|grep jesse|awk '{print $1}') ; echo $cluster
Outputs:
jesse-gke1
jesse-gke2
How can I get both of the output items in a command that would look like:
gcloud someaction jesse-gke1 zone=us-eastx-x
and iterate through the results?
Thanks!
echo $cluster
instead ofecho "$cluster"
. When you require your shell to perform word splitting then quotes are not needed. – marc Feb 14 '22 at 14:12awk
take args from stdin? Try putting xargs in your pipeline just before awk, or just replacingawk
in your command withxargs /full/path/to/awk
– Nate T Feb 14 '22 at 14:15