google-cloud-sdk
google-cloud-sdk copied to clipboard
Unexpected 0 return code from `echo "" | gcloud auth application-default print-access-token` when unauthenticated
I am trying to suppress the password prompt for gcloud auth application-default print-access-token. When piping echo "" into that command, I expect:
- The password prompt to be suppressed
- A nonzero return code, as the authentication failed (empty password)
In actuality, it suppresses the password prompt, but it gives a 0 return code. I think this is a bug, it should have a nonzero return code because it's a failed authentication.
> gcloud auth application-default print-access-token
Reauthentication required.
Please enter your password:
Command killed by keyboard interrupt
> echo $?
130
> echo "" | gcloud auth application-default print-access-token
> echo $?
0
I have the below version on macOS Sonoma version 14.3:
> gcloud --version
Google Cloud SDK 468.0.0
bq 2.0.101
core 2024.03.08
gcloud-crc32c 1.0.0
gsutil 5.27