TranslateProject/translated/tech/20221022.3 ⭐️⭐️ Use open source commands in Powershell.md

94 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[#]: subject: "Use open source commands in Powershell"
[#]: via: "https://opensource.com/article/22/10/set-path-powershell"
[#]: author: "Alan Smithee https://opensource.com/users/alansmithee"
[#]: collector: "lkxed"
[#]: translator: "qfzy1233"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
在Powershell 中使用开源命令
======
当你在操作系统上启动应用程序时操作系统需要使用某些代码库和实用程序来运行该应用程序。你的操作系统知道如何找到这些库和实用程序因为它有一个_系统路径_一个到许多应用程序都需要用到的公共共享数据的映射。所有操作系统都有这一点但用户通常不会意识到这一点因为他们通常不需要在意它。然而当你需要编程或使用特殊的网络实用程序或命令时你可能需要关心你自己的PATH变量配置。
PATH变量使你可以将命令保存到一致的位置并使用命令提示符或更强大(也是开源的)[Powershell][1]从系统上的任何位置调用它们。
例如假设你想安装开源应用程序“pscp.exe”它是Windows上著名的PuTTY OpenSSH客户端的命令行界面。你可以将它下载到你的硬盘但是你的命令行如何知道它的存在呢?实时一开始,它并不知道:
```
PS> pscp
pscp: 命令“pscp”不能被识别为cmdlet、脚本文件或可操作程序的名称。检查名称的拼写或者如果包含了路径则检查路径是否正确然后再试一次。
```
如果你正在使用一个开源命令行例如Powershell或[Cmder][2],那么你将得到一个有用的错误提示,提示这可能是你的路径有问题(或没有问题)。下面是解决这个问题的方法。
### 设置 PATH
- 首先,在桌面上创建一个名为`App`的文件夹。
- 接下来右键单击屏幕左下角的Windows菜单然后选择 **系统**.
![Image of the Windows menu system.][3]
Image by:
(Alan Smithee, CC BY-SA 4.0)
- 在弹出的“**系统**”窗口中,单击窗口左侧的“**高级系统设置**”链接。
- 在出现的**系统属性**窗口中,单击窗口底部的**环境变量**按钮。
![Image Windows system enviroment variables.][4]
Image by:
(Alan Smithee, CC BY-SA 4.0)
- 在**环境变量**窗口中,单击**用户变量**面板下的**新建**按钮。
![Image of new Windows enviroment variables.][5]
Image by:
(Alan Smithee, CC BY-SA 4.0)
- 在弹出的对话框中,为**变量名**字段输入`PATH`,为**变量值**字段输入 `%USERPROFILE\Desktop\App` 。单击**OK**按钮保存更改。
![Image of Windows path set.][6]
Image by:
(Alan Smithee, CC BY-SA 4.0)
将那些你希望从命令提示符在`Desktop\Apps`和Powershell, CmderCmd中调用的命令和应用程序放置于`Desktop\Apps`路径下:
```
PS> pscp version
pscp: Release 0.XY
Build platform: 64-bit x86 Windows
PS>
```
### PATH路径自动设置
许多应用程序会在安装过程中自动添加到系统路径中。然而,并不是所有的程序都如此,要么是因为你在安装过程中遗漏了一个复选框,要么是因为应用程序开发人员希望你自己添加它。当自动路径失败时,你现在知道如何自己设置路径。
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/10/set-path-powershell
作者:[Alan Smithee][a]
选题:[lkxed][b]
译者:[qfzy1222](https://github.com/qfzy1233)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/alansmithee
[b]: https://github.com/lkxed
[1]: https://opensource.com/article/18/2/powershell-people
[2]: http://cmder.app/
[3]: https://opensource.com/sites/default/files/2022-10/windows-menu-system.png
[4]: https://opensource.com/sites/default/files/2022-10/windows-system-environment-variables.png
[5]: https://opensource.com/sites/default/files/2022-10/windows-environment-variables-new.png
[6]: https://opensource.com/sites/default/files/2022-10/windows-path-set.png