Appendix A. Syntax and Grammar
This appendix covers the basic syntax and grammar rules of MSH and should be a useful reference while learning MSH. For an exhaustive list of the syntax and grammar intricacies, use the built-in help system (get-help
).
Cmdlets
All cmdlets follow an enforced verb-noun naming convention of the form verb-noun
. If a verb is omitted, the get-
form of cmdlet is used.
Operators
Operators are used universally for setting, modifying, and comparing information as it passes around the shell.
Arithmetic
The arithmetic operators allow mathematical calculations within the shell. Table A-1 describes the available arithmetic operators and shows how they are used with numbers.
Operator |
Description |
Example |
Result |
+ |
Add two numbers |
8+2 |
10 |
- |
Subtract one number from another Negate a number |
8–2 -8 |
6 -8 |
* |
Multiply two numbers |
8*2 |
16 |
/ |
Divide one number by another |
8/2 |
4 |
( ) |
Change calculation order and evaluate the enclosed first |
(8–6)*2 |
4 |
% |
Remainder of a division (modulus) |
8%3 |
2 |
When multiple arithmetic operators are combined in a single expression, MSH follows a precedence sequence for evaluation. The unary - operator (negate a number) will always be evaluated first, followed by multiply (*
), divide (/
), remainder (%
), add (+
), and subtract (-
). Parentheses ((expression)
) can be used to override the default operator-evaluation order.
Some arithmetic operators are overloaded for other types. In particular, when ...
Get Monad (AKA PowerShell) now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.