bash 如何为 gcloud 启用 shell 命令完成?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46236580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable shell command completion for gcloud?
提问by Kurt Peek
I'm trying to install the Google Cloud SDK on a Mac (following https://cloud.google.com/sdk/docs/quickstart-mac-os-x), using the install.sh
script:
我正在尝试使用脚本在 Mac 上安装 Google Cloud SDK(遵循https://cloud.google.com/sdk/docs/quickstart-mac-os-x)install.sh
:
~/Downloads$ ./google-cloud-sdk/install.sh
In the logged output, I see the following instructions:
在记录的输出中,我看到以下说明:
==> Source [/Users/kurtpeek/Downloads/google-cloud-sdk/completion.bash.inc] in your profile to enable shell command completion for gcloud.
==> Source [/Users/kurtpeek/Downloads/google-cloud-sdk/path.bash.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.
Indeed, I find that using the gsutil
command still leads to a -bash: gsutil: command not found
error, so I still probably have to perform this step.
确实,我发现使用该gsutil
命令仍然会导致-bash: gsutil: command not found
错误,因此我可能仍然需要执行此步骤。
It is not entirely clear to me, however, what is meant by these instructions. I'm on a Mac and my bash profile is ~/.bash_profile
. What lines would I have to add in order to make the command line completion work?
然而,我并不完全清楚这些说明的含义。我在 Mac 上,我的 bash 配置文件是~/.bash_profile
. 我必须添加哪些行才能使命令行完成工作?
Update
更新
The first time I installed I did not use sudo
. Reinstalling with sudo
, I get an additional prompt whether to modify my bash profile, which upon accepting leads to the following lines added to my .bash_profile
:
我第一次安装时没有使用sudo
. 使用 重新安装sudo
,我收到一个额外提示是否修改我的 bash 配置文件,在接受后会导致以下行添加到我的.bash_profile
:
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/kurtpeek/Downloads/google-cloud-sdk/path.bash.inc' ]; then source '/Users/kurtpeek/Downloads/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/kurtpeek/Downloads/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/kurtpeek/Downloads/google-cloud-sdk/completion.bash.inc'; fi
However, I still get gsutil: command not found
errors.
但是,我仍然遇到gsutil: command not found
错误。
回答by Kurt Peek
The trick was to run the install.sh
using sudo
as described in the update. After that I needed to restart the terminal (as described in the instructions) for the changes to take effect.
诀窍是按照更新中的描述运行install.sh
using sudo
。之后,我需要重新启动终端(如说明中所述)以使更改生效。
回答by Tushar Phatangare
For Mac Run below command to run the install.sh
:
对于 Mac 运行下面的命令来运行install.sh
:
sudo chmod +x install.sh
sudo chmod +x install.sh