PowerShell Core for Linux Administrators Cookbook
上QQ阅读APP看书,第一时间看更新

Convenience aliases

One important point to note is that commands such as ls and mkdir are aliases in Windows PowerShell, which means that running ls on Windows PowerShell would run Get-ChildItem in the background (this is also true for PowerShell on Windows). In Linux, however, running ls from within PowerShell would run the actual ls command; ls is not an alias in PowerShell on Linuxit is the command itself, whose output would be plain text. You can validate this by running ls | Get-Member on PowerShell on Linux, and comparing it with PowerShell on Windows as well as Windows PowerShell (it is, therefore, good to stick to the best practice of not using aliases in scripts):

PowerShell knows whether it is running on Linux, Windows, or macOS by means of the values of the automatic variables  IsLinux, IsWindows, and IsMacOS. On any system, only one of these variables has the value  True. When PowerShell sees that IsLinux is True, it would run Linux commands instead of the convenience aliases that were initially created to facilitate Linux administrators. For more information on these automatic variables, read the  Configuring built-in variables recipe.