windowsamazon-web-servicespowershellbackticks

Escape (Grave) Character in Powershell


The recommended installation instructions for AWS Copilot on Windows are:

New-Item -Path 'C:\copilot' -ItemType directory; `
  Invoke-WebRequest -OutFile 'C:\copilot\copilot.exe' https://github.com/aws/copilot-cli/releases/latest/download/copilot-windows.exe

According to the Microsoft guide, the escape character has a ton of usages, but I don't understand how it is being used in the statement given to us by Amazon to install Copilot.

Could someone clarify the usage of ` in the first line?

[the code works fine, just wondering about usage]


Solution

  • The backtick ` can be used as a line continuation, for instance, when dealing with multiple parameters.

    A simple example of valid syntax:

    Get-ChildItem `
        -Path . `
        -Filter *.ps1 `
        -File
    

    However, this usage can 100% of the times be replaced for a better / cleaner form of parameter binding, called splatting:

    $getChildItemSplat = @{
        Path   = '.'
        Filter = '*.ps1'
        File   = $true
    }
    Get-ChildItem @getChildItemSplat
    

    For the specifics of your question, the ` is completely unnecessary and the same can be said for the ;.

    The following would work as well:

    New-Item -Path 'C:\copilot' -ItemType Directory
    Invoke-WebRequest -OutFile 'C:\copilot\copilot.exe' https://github.com/aws/copilot-cli/releases/latest/download/copilot-windows.exe