LoginSignup
2
1

More than 5 years have passed since last update.

gcloudのprojectをShellScript内でのみ切り替える

Last updated at Posted at 2018-08-18

gcloud config configurations activateを使うと、全てのShellで切り替わるため、複数の仕事を同時にしている場合に事故る。(prodとdevで異なるProjectを使うなど)

そのShellScriptだけで有効化したい場合、以下のようにする。

#!/bin/bash

gcloud() {
    `which gcloud` --project=myproject $*
}

gcloud dns managed-zones list

note

  • alias はShellScriptでは使えない。使えるようにする方法があるが、事故りそう。
  • gcloud(){ gcloud ...}とすると、無限ループするので、which gcloudで回避。
  • zoneとregionも指定したいけど、そこはconfigで。--projectの代わりに、--configurationもできる。
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1