使用 Write-Output 在 powershell 中回顯變數

使用 Write-Output 在 powershell 中回顯變數

我剛剛使用控制面板在 Windows 10 中設定了幾個變數。

變數:TWILIO_ACCOUNT_SID 變數值:my_account_sid

變數:TWILIO_AUTH_TOKEN 變數值:my_twilio_auth_token

refreshenv在 powershell 中執行此操作,以便可以看到新值。

但是當我這樣做時:

Write-Output "$TWILIO_ACCOUNT_SID"
Write-Output "$TWILIO_ACCOUNT_SID"

我只得到空行而不是值。我究竟做錯了什麼?

答案1

在Powershell中您可以使用ENV:VariableName磁碟機來呼叫環境變數。

例子:

Get-ChildItem ENV:systemroot

Name                           Value
----                           -----
SystemRoot                     C:\WINDOWS

在你的情況下,你可以稱之為Write-Output "ENV:TWILIO_ACCOUNT_SID"

相關內容