10

I was trying out a command by typing the path to it, and when I hit TAB, this happened:

C:\> C:\Program Files\KeePassXC\keepass<TAB>
# became this:
C:\> & 'C:\Program Files\KeePassXC\keepassxc-cli.exe'

Does it simply evaluate a string? At least, I assume so as the path needs to be enclosed in quotes because of the spaces in it, and without & I get the following error:

C:\> 'C:\Program Files\KeePassXC\keepassxc-cli.exe' --help

At line:1 char:50

  • 'C:\Program Files\KeePassXC\keepassxc-cli.exe' --help
  •                                              ~~~~
    

Unexpected token 'help' in expression or statement. At line:1 char:1

  • 'C:\Program Files\KeePassXC\keepassxc-cli.exe' --help
  • 
    

The '--' operator works only on variables or on properties. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken

Would you link to the documentation? Thank you!


The threads discussing & (1, 2) are about something else completely (or I missed to find a connection).

toraritte
  • 1,128

1 Answers1

13

That's a call or invocation operator Call operator &:

You can use the call operator to execute scripts using their filenames. The example below shows a script filename that contains spaces. When you try to execute the script, PowerShell instead displays the contents of the quoted string containing the filename. The call operator allows you to execute the contents of the string containing the filename.

PS C:\Scripts> ".\script name with spaces.ps1"
.\script name with spaces.ps1

PS C:\Scripts> & ".\script name with spaces.ps1" Hello World!

toraritte
  • 1,128
M. Behrens
  • 1,346