1

I am running a pipeline that uses a powershell script and I need to bind a tag I created to my Firestore database in Google Cloud Platform

the gcloud command to do this is as follows:

gcloud resource-manager tags bindings create --tag-value=$value --parent=//firestore.googleapis.com/projects/$projectID/databases/\(default\) --location=$location

I have tested this in Google CLI and it works. However when running it in my powershell script I am encountering the error below

 default\: /__w/1/build-bundle-00x-00x-general-extract/infra/00x-00x-general/.terraform/modules/gcp_firestore_enable_ttl/scripts/enable_ttl.ps1:60
 Line |
   60 |  … store.googleapis.com/projects/$projectID/databases/\(default\) --loca …
      |                                                         ~~~~~~~~
      | The term 'default\' is not recognized as a name of a cmdlet,
      | function, script file, or executable program. Check the
      | spelling of the name, or if a path was included, verify that
      | the path is correct and try again.

I have tried the command using bash script and Google Command Line Interface and works as intended with no errors. I am only experiencing this error when using powershell script.

1 Answer 1

0

In PowerShell, only ` (the so-called backtick) serves as the escape character, not \.

  • That is, \ has no special meaning to PowerShell and is used verbatim.

Therefore, it must be `(default`), not \(default\) in order to designate the unquoted use of ( and ) as verbatim, i.e. to pass verbatim string (default):

# Note the `(default`) instead of `\(default\)`
gcloud resource-manager tags bindings create --tag-value=$value --parent=//firestore.googleapis.com/projects/$projectID/databases/`(default`) --location=$location

Alternatively, use quoting; since you're referencing a variable as part of the argument, you must use an expandable (double-quoted) string ("..."):

# "..." around the whole argument
gcloud resource-manager tags bindings create --tag-value=$value "--parent=//firestore.googleapis.com/projects/$projectID/databases/(default)" --location=$location

Note:

  • Partial quoting would work too; by quoting only the (default) part, you can use a verbatim (single-quoted) string ('...'):

    --parent=//firestore.googleapis.com/projects/$projectID/databases/'(default)'
    
  • However, note that this only works if the argument starts with an unquoted token (which is true here); see this answer for background information.


As for why PowerShell didn't choose \ as the escape character:

  • Since \ is the path separator on Windows (and PowerShell has Windows-only roots), this would have made specifying file-system paths quite cumbersome, due to the resulting need to escape such separators (e.g. C:\\Foo\\Bar to refer to C:\Foo\Bar). See the bottom section of this answer for a detailed discussion.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.