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
List all environment variables from the command line
提问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 prefix
to 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
回答by Boyce Field
You can use SET
in cmd
您可以SET
在 cmd 中使用
To show the current variable, just SET
is 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 set
to 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, 例子)