Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto answer yes for command `gcloud compute instance-templates delete`

To delete a gcloud instance template, we call

gcloud compute instance-templates delete TEMPLATE_NAME

But we have to answer a Y/n question which is not favored for automation bash script. We want auto answer yes, how?

p.s.

My google search for this question results little helpful.

Manual page of the command also has nothing about any other parameter.

gcloud help   compute instance-templates delete
like image 450
Nam G VU Avatar asked Feb 18 '19 16:02

Nam G VU


People also ask

How do I exit gcloud from command line?

For example, to work with gcloud compute , type gcloud compute and then press F7 . You can then type subcommands such as list without needing to first type gcloud compute . When you're no longer using the command, press Ctrl-C and F7 to clear the context. To exit the interactive shell press Ctrl-D or F9 .


2 Answers

gcloud has a set of global flags including --quiet to disable such prompts:

https://cloud.google.com/sdk/gcloud/reference/

like image 51
DazWilkin Avatar answered Oct 08 '22 12:10

DazWilkin


I agree that using --quiet is the best way in the case of gcloud commands.

But for a CLI tool that doesn't have such an option we can explicitly use printf like below:

printf 'yes' | gcloud compute instance-templates delete TEMPLATE_NAME

I hope this is useful (if not in this case, then somewhere else).

like image 24
Amit Yadav Avatar answered Oct 08 '22 12:10

Amit Yadav