Fixes #7557 * Adds support for binary parsing in format echoing hex: `0b11010110` * Works with all existing type suffixes and multipliers. * Supports arbitrary length parsing with `n` suffix using BigInteger; details below. * Adds `NumberFormat` enum to specify hex/binary/base 10 for the tokenizer, replacing old `bool hex`. * Adds `n` suffix for all numeric literals to support returning value as a `BigInteger` if requested. This bypasses the issue of large literals losing accuracy when they cast through `double`. * Adds tests for all new behaviours. --- ### Binary / Hex Parsing Implementation * Mimics old sign bit behaviour for int and long types. Sign bits accepted for 8 or 16-bit Hex parsing, and 8, 16, 32, 64 for binary. * i.e., `0xFFFFFFFF -eq ([int]-1)` and `0xFFFFFFFFFFFFFFFF -eq ([long]-1)`, but suffixing `u` creates `int.MaxValue` and `long.MaxValue`, respectively, instead. * Sign bits higher than this are accepted for bigint-suffixed numerals: * Hex: Bigint-suffixed hex treats the high bit of any literal with a length multiple of 8 as the sign bit * Binary: Bigint-suffixed binary accepts sign bits at 96 and 128 chars, and from there on every 8 characters. * Prefixing the literal with a 0 will bypass this and be treated as unsigned, e.g. `0b011111111` * Specifying an `u`nsigned suffix (or combination suffix that includes `u`) ignores sign bits, similar to how parsing a hex string using `[Convert]::ToUint32()` would do so. * Supports negating literals using `-` prefix. This can result in positive numbers due to sign bits being permitted, just like hex literals. --- ### Refactored numeric tokenizer parsing **New flow:** 1. Check for `real` (`.01`, `0.0`, or `0e0` syntaxes) 1. If the decimal suffix is present, TryParse directly into decimal. If the TryParse fails, TryGetNumberValue returns `false`. 2. TryParse as `Double`, and apply multiplier to value. If the TryParse fails, TryGetNumberValue returns `false`. 1. Check type suffixes and attempt to cast into appropriate type. This will return `false` if the value exceeds the specified type's bounds. 2. Default to parsing as `double` where no suffix has been applied. 2. Check number format. * If binary, manually parse into BigInteger using optimized helper function to directly construct the BigInteger bytes from the string. * If hex, TryParse into `BigInteger` using some special casing to retain original behaviours in int/long ranges. * If neither binary nor hex, TryParse normally as a `BigInteger`. 3. Apply multiplier value before attempting any casts to ensure type bounds can be appropriately checked without overflows. 4. Check type suffixes. * If a specific type suffix is used, check type bounds and attempt to parse into that type. * If the value exceeds the type's available values, the parse fails. Otherwise, a straight cast is performed. 5. If no suffix is used, the following types are bounds-checked, in order, resulting in the first successful test determining the type of the number. * `int` * `long` * `decimal` (base-10 literals only) * `double` (base-10 literals only) * ~~`BigInteger` for binary or hex literals.~~ If the value is outside `long` range (for hex and binary) or `double` range (for base 10), the parse will fail; higher values must be explicitly requested using the `n`/`N` BigInteger suffix. --- *This is a breaking change* as binary literals are now read as numbers instead of generic tokens which could potentially have been used as function / cmdlet names or file names. Notes: * Binary literal support was approved by the committee in #7557 * ~~The same issue is still under further discussion for underscore support in numeric literals and whether BigInteger parsing ought to be exposed to the user at all.~~ * ~~Supporting underscore literals is a further breaking change causing some generic tokens like `1_000_000` to be read as numerals instead.~~ Per @SteveL-MSFT's [comment](https://github.com/PowerShell/PowerShell/pull/7993#issuecomment-442651543) this proposal was rejected. * ~~Removing underscore support or preventing standard parsing from accepting BigInteger ranges is a relatively trivial matter. It is my personal opinion that there is no particular reason *not* to hand the user a BigInteger when they enter a sufficiently large literal, but I will defer to the PowerShell Committee's judgement on this.~~
PowerShell
Welcome to the PowerShell GitHub Community! PowerShell Core is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets.
Windows PowerShell vs. PowerShell Core
Although this repository started as a fork of the Windows PowerShell code base, changes made in this repository do not make their way back to Windows PowerShell 5.1 automatically. This also means that issues tracked here are only for PowerShell Core 6. Windows PowerShell specific issues should be opened on UserVoice.
New to PowerShell?
If you are new to PowerShell and would like to learn more, we recommend reviewing the getting started documentation.
Get PowerShell
You can download and install a PowerShell package for any of the following platforms.
| Supported Platform | Downloads (stable) | Downloads (preview) | How to Install |
|---|---|---|---|
| Windows (x64) | .msi | .msi | Instructions |
| Windows (x86) | .msi | .msi | Instructions |
| Ubuntu 18.04 | .deb | .deb | Instructions |
| Ubuntu 16.04 | .deb | .deb | Instructions |
| Ubuntu 14.04 | .deb | .deb | Instructions |
| Debian 9 | .deb | .deb | Instructions |
| CentOS 7 | .rpm | .rpm | Instructions |
| Red Hat Enterprise Linux 7 | .rpm | .rpm | Instructions |
| openSUSE 42.3 | .rpm | .rpm | Instructions |
| Fedora 27, Fedora 28 | .rpm | .rpm | Instructions |
| macOS 10.12+ | .pkg | .pkg | Instructions |
| Docker | Instructions |
You can download and install a PowerShell package for any of the following platforms, which are supported by the community.
| Platform | Downloads (stable) | Downloads (preview) | How to Install |
|---|---|---|---|
| Arch Linux | Instructions | ||
| Kali Linux | .deb | .deb | Instructions |
| Many Linux distributions | Snapcraft | Snapcraft |
You can also download the PowerShell binary archives for Windows, macOS and Linux.
| Platform | Downloads (stable) | Downloads (preview) | How to Install |
|---|---|---|---|
| Windows | 32-bit/64-bit | 32-bit/64-bit | Instructions |
| macOS | 64-bit | 64-bit | Instructions |
| Linux | 64-bit | 64-bit | Instructions |
| Windows (arm) Experimental | 32-bit/64-bit | 32-bit/64-bit | Instructions |
| Raspbian (Stretch) Experimental | .tgz | 32-bit/64-bit | Instructions |
To install a specific version, visit releases.
Community Dashboard
Dashboard with visualizations for community contributions and project status using PowerShell, Azure, and PowerBI.
For more information on how and why we built this dashboard, check out this blog post.
Chat Room
Want to chat with other members of the PowerShell community?
We have a Gitter Room which you can join below.
There is also the community driven PowerShell Slack Team which you can sign up for at Slack.
Add-ons and libraries
Awesome PowerShell has a great curated list of add-ons and resources.
Building the Repository
| Linux | Windows | macOS |
|---|---|---|
| Instructions | Instructions | Instructions |
If you have any problems building, please consult the developer FAQ.
Build status of nightly builds
| Azure CI (Windows) | Azure CI (Linux) | Azure CI (macOS) | Code Coverage Status | CodeFactor Grade |
|---|---|---|---|---|
Downloading the Source Code
You can just clone the repository:
git clone https://github.com/PowerShell/PowerShell.git
See working with the PowerShell repository for more information.
Developing and Contributing
Please see the Contribution Guide for how to develop and contribute. If you are developing .NET Core C# applications targeting PowerShell Core, please check out our FAQ to learn more about the PowerShell SDK NuGet package.
Also, make sure to check out our PowerShell-RFC repository for request-for-comments (RFC) documents to submit and give comments on proposed and future designs.
Support
For support, please see the Support Section.
Legal and Licensing
PowerShell is licensed under the MIT license.
Windows Docker Files and Images
License: By requesting and using the Container OS Image for Windows containers, you acknowledge, understand, and consent to the Supplemental License Terms available on Docker Hub:
Telemetry
By default, PowerShell collects the OS description and the version of PowerShell (equivalent to $PSVersionTable.OS and $PSVersionTable.GitCommitId) using Application Insights.
To opt-out of sending telemetry, create an environment variable called POWERSHELL_TELEMETRY_OPTOUT set to a value of 1 before starting PowerShell from the installed location.
The telemetry we collect fall under the Microsoft Privacy Statement.
Governance
Governance policy for PowerShell project is described here.
Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.