Skip to content

微软 PowerShell

给四个名称张三、李四、Alice、Bob ,排序方案有:

  • 存储,编码
  • 存储,两个字段,对存储空间有要求
  • 计算,代码,对计算性能有要求

为了示好各国政府、企业,早期微软选择了编码方案,进入互联网时代就有些不合时宜了。你做了一个网站,用户上传的文件编码各异。

Windows 命令行工具,有 cmd 、powershell 、pwsh 三种。

CMD 陈旧,有编码问题,但兼容性好。

Windows PowerShell ,非跨平台,命令为 powershell 。

PowerShell ,跨平台,命令为 pwsh 。Bash 面向文本,PowerShell 面向对象。

面向对象,功能强大,但复杂度提升。Get-Content 读取文件,默认返回数组,文本每行对应一个数组元素,使用 -Raw 返回文本。将打印数组和打印文本做得差不多,微软真是出人才。

'Hello World
Hello Human' | Out-File a.txt

Get-Content a.txt

(Get-Content a.txt).length

Get-Content a.txt -Raw

Ubuntu 安装 PowerShell

sudo snap install powershell --classic

Ubuntu 卸载 PowerShell

sudo snap remove powershell

基于别名系统, PowerShell 相当程度上兼容 CMD 、Bash 。

Get-Alias
命令别名
Clear-Hostclear
Copy-Itemcp
Get-ChildItemls
Get-Contentcat
Get-Locationpwd
Move-Itemmv
Remove-Itemrm
Set-Locationcd
Write-Outputecho

Windows 安装 Git ,附带安装 Git Bash ,可以使用 sed 、diff 等命令。

联系 math@baima.site