Stackoverflow热门问题(二十一)-在Cmd里显示环境变量

stackoverflow热门问题目录

如有翻译问题欢迎评论指出,谢谢。

在Cmd里显示环境变量

  • Nicola Cossu asked:
    • 怎么在Windows的Cmd里面列出所有环境变量?
    • 等效于powershell的gci env:命令,或者ls env:dir env:
  • Answers:
    • Jon – vote: 1472
    • 这样:
    • SET
    • 想看某前缀的环境变量的话,用 SET 前缀来查询。
    • 例如,只想获取derbydb的环境变量,就这样:
    • set derby
    • …将会得到输出:
    • DERBY_HOME=c:\Users\amro-a\Desktop\db-derby-10.10.1.1-bin\db-derby-10.10.1.1-bin
    • Fetchez la vache – vote: 179
    • Jon的答案可行,不过可以用语法糖来扩展它。
    • SET | more
    • 上面的命令将会在一页里面展示环境变量,而不是完全列出。此外
    • SET output.txt
    • 可以将输出写入到output.txt文件中,方便进一步操作。
    • user52028778 – vote: 127
    • 在powershell里列出所有环境变量:
    • Get-ChildItem Env:
    • 如user797717建议的避免输出截断:
    • Get-ChildItem Env: | Format-Table -Wrap -AutoSize
    • 参考: Creating and Modifying Environment Variables (Windows PowerShell Tip of the Week)

List all environment variables from the command line

  • Nicola Cossu asked:
    • Is it possible to list all environment variables from a Windows\’ command prompt?
      怎么在Windows的Cmd里面列出所有环境变量?
    • Something equivalent to PowerShell\’s gci env: (or ls env: or dir env:).
      等效于powershell的gci env:命令,或者ls env:dir env:
  • Answers:
    • Jon – vote: 1472
    • Just do:
      这样:
    • SET
    • You can also do SET prefix to see all variables with names starting with prefix.
      想看某前缀的环境变量的话,用 SET 前缀来查询。
    • 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
    • Fetchez la vache – vote: 179
    • Jon has the right answer, but to elaborate a little more with some syntactic sugar..
      Jon的答案可行,不过可以用语法糖来扩展它。
    • 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 Notepad or whatever…
      可以将输出写入到output.txt文件中,方便进一步操作。
    • user52028778 – vote: 127
    • 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)
      参考: Creating and Modifying Environment Variables (Windows PowerShell Tip of the Week)

You may also like...

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注