windows 从命令行列出所有环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5327495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:11:12  来源:igfitidea点击:

List all environment variables from the command line

windowscommand-lineenvironment-variablesprompt

提问by Nicola Cossu

Is it possible to list allenvironment variables from a Windows' command prompt?

是否可以从 Windows 的命令提示符列出所有环境变量?

Something equivalent to PowerShell's gci env:(or ls env:or dir env:).

相当于 PowerShell gci env:(或ls env:or dir env:) 的东西。

回答by Jon

Just do:

做就是了:

SET

You can also do SET prefixto see all variables with names starting with prefix.

您还SET prefix可以查看名称以prefix.

For example, if you want to read only derbydb from the environment variables, do the following:

例如,如果您只想从环境变量中读取 derbydb,请执行以下操作:

set derby 

...and you will get the following:

...你会得到以下信息:

DERBY_HOME=c:\Users\amro-a\Desktop\db-derby-10.10.1.1-bin\db-derby-10.10.1.1-bin

回答by Fetchez la vache

Jon has the right answer, but to elaborate a little more with some syntactic sugar..

乔恩有正确的答案,但要详细说明一些语法糖..

SET | more

enables you to see the variables one page at a time, rather than the whole lot, or

使您能够一次一页地查看变量,而不是整个批次,或者

SET > output.txt

sends the output to a file output.txt which you can open in Notepador whatever...

将输出发送到文件 output.txt 中,您可以在记事本或其他任何地方打开该文件...

回答by user52028778

To list all environment variables in PowerShell:

在 PowerShell 中列出所有环境变量:

Get-ChildItem Env:

Or as suggested by user797717 to avoid output truncation:

或者按照 user797717 的建议避免输出截断:

Get-ChildItem Env: | Format-Table -Wrap -AutoSize

Source: Creating and Modifying Environment Variables(Windows PowerShell Tip of the Week)

来源:创建和修改环境变量本周 Windows PowerShell 提示

回答by Grant Thomas

Simply run setfrom cmd.

只需setcmd.

Displays, sets, or removes environment variables. Used without parameters, set displays the current environment settings.

显示、设置或删除环境变量。不带参数使用,set 显示当前环境设置。

回答by Boyce Field

You can use SETin cmd

您可以SET在 cmd 中使用

To show the current variable, just SETis enough

要显示当前变量,就SET足够了

To show certain variable such as 'PATH', use SET PATH.

要显示某些变量,例如“PATH”,请使用SET PATH.

For help, type set /?.

如需帮助,请键入set /?

回答by Pawe? Piwowar

Don't lose time. Search for it in the registry:

不要浪费时间。在注册表中搜索它:

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

returns less than the SET command.

返回小于 SET 命令。

回答by Abhishek Gurjar

As mentioned in other answers, you can use setto list all the environment variables or use

如其他答案中所述,您可以使用set列出所有环境变量或使用

set [environment_variable]to get a specific variable with its value.

set [environment_variable]获取具有其值的特定变量。

set [environment_variable]=can be used to remove a variable from the workspace.

set [environment_variable]=可用于从工作区中删除变量。

回答by captain puget

If you want to see the environment variable you just set, you need to open a new command window.

如果要查看刚刚设置的环境变量,则需要打开一个新的命令窗口。

Variables set with setx variables are available in future command windows only, not in the current command window. (Setx, Examples)

使用 setx 变量设置的变量仅在未来的命令窗口中可用,在当前的命令窗口中不可用。( Setx, 例子)