Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the command of call operator &?

Tags:

powershell

I used ls alias: and tried to find &. However, & is not in the output. What's &? Is it the combination of Invoke-Command and Invoke-Expression?

Are there any other operators which don't have a cmdlet in PowerShell?

like image 415
ca9163d9 Avatar asked Feb 22 '17 04:02

ca9163d9


People also ask

What is call operator in PowerShell?

The call operator, also known as the "invocation operator", lets you run commands that are stored in variables and represented by strings or script blocks. The call operator executes in a child scope.

What does @() mean in PowerShell?

What is @() in PowerShell Script? In PowerShell, the array subexpression operator “@()” is used to create an array. To do that, the array sub-expression operator takes the statements within the parentheses and produces the array of objects depending upon the statements specified in it.

What does $_ mean in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.


1 Answers

The call operator & allows you to execute a command, script or function.

Many times you can execute a command by just typing its name, but this will only run if the command is in the environment path. Also if the command (or the path) contains a space then this will fail. Surrounding a command with quotes will make PowerShell treat it as a string, so in addition to quotes, use the & call operator to force PowerShell to treat the string as a command to be executed.

PowerShell Call Operator

I am not sure of all the operators that are in PowerShell, but another really useful one is --%, used to stop parsing.

The stop-parsing symbol --%, introduced in PowerShell 3.0, directs PowerShell to refrain from interpreting any further input on the line as PowerShell commands or expressions.

PowerShell Stop Parsing Operator

Building on the comments that have been made:

Get-Help About_Operators

It will show you the best overview of all operator types and abstract ones like the Call and Stop Parsing Operators.

like image 109
Lachie White Avatar answered Sep 28 '22 08:09

Lachie White