早在去年八月份PowerShell就开始开源跨平台了,但是一直没有去尝试,叫做PowerShell Core。
这里打算简单介绍一下如何安装和简单使用,为还不知道PowerShell Core on Ubuntu的同学们提供一点小小的入门帮助,谢谢大家支持~
PowerShell Core是由Microsoft开发的运行在.Net Core上的开源跨平台的任务自动化和配置管理系统。
[b]1.在Ubuntu 16.04上安装PowerShell Core[/b]
a)导入公共存储库GPG秘钥
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
b)注册微软Ubuntu存储库
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
c)更新软件包
d)安装PowerShell
sudo apt-get install -y powershell
[b]2.使用PowerShell Core[/b]
a) 启动PowerShell并检查PowerShell版本:
[img]http://files.jb51.net/file_images/article/201706/201706150839092.png[/img]
b) 添加了一些集成变量,可以用来判断检查系统版本:
[img]http://files.jb51.net/file_images/article/201706/201706150839093.png[/img]
c) 获取可用的模块:
[img]http://files.jb51.net/file_images/article/201706/201706150839094.png[/img]
d) 利用管道:
[img]http://files.jb51.net/file_images/article/201706/201706150839095.png[/img]
e) 使用别名:
[img]http://files.jb51.net/file_images/article/201706/201706150839096.png[/img]
f) 使用.NET类库:
[img]http://files.jb51.net/file_images/article/201706/201706150839097.png[/img]
[b]3. 基本命令对照表[/b]
[img]http://files.jb51.net/file_images/article/201706/201706150839098.png[/img]
[b]4. Linux上的PowerShell Core的注意事项[/b]
a) 大小写敏感
Windows是忽略大小写的,所以Windows上的PowerShell也是忽略的。然而Linux是大小写敏感的。因此Linux上的PowerShell一般情况下是忽略大小写的,但是一些操作系统级别的特殊值是大小写敏感的(比如一些环境变量的名字):
[img]http://files.jb51.net/file_images/article/201706/201706150839099.png[/img]
b) 别名
Windows上的PowerShell有一些Linux类型的别名,比如ls、cat、man、etc等,然而,这些别名在Linux上为了防止冲突已经不存在了,如下例子,ls在Windows PowerShell中也是Get-ChildItem的别名,而在Linux PowerShell Core中查不到:
[img]http://files.jb51.net/file_images/article/201706/2017061508390910.png[/img]
[b]5. 使用Visual Studio Code进行PowerShell脚本开发[/b]
a) 先安装Visual Studio:https://code.visualstudio.com/。
b) 添加PowerShell插件:
[img]http://files.jb51.net/file_images/article/201706/2017061508390911.png[/img]
c) 现在使用这个编写PowerShell脚本就类似于Windows中的ISE了:
[img]http://files.jb51.net/file_images/article/201706/2017061508390912.jpg[/img]
d) 更多的使用方法详见:[url=https://code.visualstudio.com/docs]https://code.visualstudio.com/docs[/url]。
以上这篇详谈Ubuntu PowerShell(小白入门必看教程)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。