1

I am writing a simple code for gcloud. In my script, I want to get a list of all projects on an account and for each of them call a gcloud command that requires user input which I want to emulate in my bash script.

projects_list=$(gcloud projects list)

for n in $projects_list
do
    gcloud projects dosomething $n
done

Every time I call gcloud projects dosomething, it asks "Do you want to continue (Y/n)?" and waits for an input from user. How do I automate this and make script emulate pressing Y?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Tim Abrams
  • 11
  • 1
  • Try: `export CLOUDSDK_CORE_DISABLE_PROMPTS=1` – William Pursell Mar 12 '21 at 18:13
  • i think that this question can help you : https://stackoverflow.com/questions/6264596/simulating-enter-keypress-in-bash-script – Ferdinando Mar 12 '21 at 22:31
  • 1
    @Ferdinando Thanks! The second answer in that thread works: `yes | gcloud projects delete` @WilliamPursell I guess that could work too. I'll just need to change it back to 0 after loop because that is the only part of the script where I want to skip prompt – Tim Abrams Mar 14 '21 at 03:12

0 Answers0