0

I am trying to provide a CLI command for users to create a specific kind of GCE instance. This means that I need to make the command as copy-and-paste-friendly as possible, while still allowing users to provide the necessary customization information (username, SSH public key).

My thoughts were something along this line:

export USERNAME=somebody
export SSH_PUBLIC_KEY="ssh-rsa abcd user@machine.com"

gcloud beta compute \
  --project=my-project instances create \
  ${USERNAME}-instance-1 --zone=us-central1-a \
  --machine-type=e2-medium --subnet=default \
  --network-tier=PREMIUM \
  --metadata=ssh-keys=${USERNAME}:${SSH_PUBLIC_KEY}

Now, as you can imagine, this fails because the SSH_PUBLIC_KEY var contains spaces.

My question is: how can I correctly escape the spaces (preferably via another command - sed?) before running gcloud beta compute, so that the command sees the key correctly?

I have already tried using "ssh-rsa\ abcd\ user@machine.com" when defining the var, but it looks like the command still sees the spaces...

Thank you!

Bogd
  • 656
  • 7
  • 16

0 Answers0