如何在powershell中为bash设置环境变量?

如何在powershell中为bash设置环境变量?,bash,visual-studio,powershell,.net-core,environment-variables,Bash,Visual Studio,Powershell,.net Core,Environment Variables,是否使用powershell设置变量(此处为“APISCRET”),以便printenv显示必要的变量 (假设问题在于Visual Studio和bash没有正确地拾取环境变量,可以从bash中设置它们。) 我在Linux上: thufir@dur:~/powershell/helloPSTwitterAPI$ thufir@dur:~/powershell/helloPSTwitterAPI$ lsb_release -a No LSB modules are available. Dist

是否使用powershell设置变量(此处为“APISCRET”),以便
printenv
显示必要的变量

(假设问题在于Visual Studio和bash没有正确地拾取环境变量,可以从bash中设置它们。)

我在Linux上:

thufir@dur:~/powershell/helloPSTwitterAPI$ 
thufir@dur:~/powershell/helloPSTwitterAPI$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.10
Release:    18.10
Codename:   cosmic
thufir@dur:~/powershell/helloPSTwitterAPI$ 
powershell代码:

Import-Module PSTwitterAPI


Set-TwitterOAuthSettings -ApiKey $env:ApiKey -ApiSecret $env:ApiSecret -AccessToken $env:AccessToken -AccessTokenSecret $env:AccessTokenSecret

#Get-TwitterUsers_Lookup -screen_name 'mkellerman'

$TwitterStatuses = Get-TwitterStatuses_UserTimeline -screen_name 'mkellerman'
#$TwitterStatuses = [array]Get-TwitterStatuses_UserTimeline -screen_name 'mkellerman'

Foreach ($status in $TwitterStatuses) {
   Write-Host $status.text
}



Write-Host "done"
Visual Studio代码:

PS /home/thufir> /home/thufir/powershell/helloPSTwitterAPI/twitter.ps1


WARNING: OAuthSettings with AccessToken '' already exists.
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At /home/thufir/.local/share/powershell/Modules/PSTwitterAPI/0.0.7/public/Invoke-TwitterAPI.ps1:34 char:5
+     Invoke-RestMethod @RestMethod_Params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.3
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At /home/thufir/.local/share/powershell/Modules/PSTwitterAPI/0.0.7/public/Invoke-TwitterAPI.ps1:34 char:5
+     Invoke-RestMethod @RestMethod_Params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.3
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
done
PS /home/thufir> 
但标准bash控制台也不是:

thufir@dur:~/powershell/helloPSTwitterAPI$ 
thufir@dur:~/powershell/helloPSTwitterAPI$ powershell twitter.ps1 
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At /home/thufir/.local/share/powershell/Modules/PSTwitterAPI/0.0.7/public/Invoke-TwitterAPI.ps1:34 char:5
+     Invoke-RestMethod @RestMethod_Params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.3
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At /home/thufir/.local/share/powershell/Modules/PSTwitterAPI/0.0.7/public/Invoke-TwitterAPI.ps1:34 char:5
+     Invoke-RestMethod @RestMethod_Params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.3
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
done
thufir@dur:~/powershell/helloPSTwitterAPI$ 
bash控制台:

thufir@dur:~/powershell/helloPSTwitterAPI$ 
thufir@dur:~/powershell/helloPSTwitterAPI$ powershell twitter.ps1 
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At /home/thufir/.local/share/powershell/Modules/PSTwitterAPI/0.0.7/public/Invoke-TwitterAPI.ps1:34 char:5
+     Invoke-RestMethod @RestMethod_Params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.3
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At /home/thufir/.local/share/powershell/Modules/PSTwitterAPI/0.0.7/public/Invoke-TwitterAPI.ps1:34 char:5
+     Invoke-RestMethod @RestMethod_Params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.3
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
done
thufir@dur:~/powershell/helloPSTwitterAPI$ 
bash控制台,但在powershell中:

PS /home/thufir/powershell/helloPSTwitterAPI> 
PS /home/thufir/powershell/helloPSTwitterAPI> ./twitter.ps1
WARNING: OAuthSettings with AccessToken '17639841-ZltXv9qW0zlW60WNy2MtcAZ0FEljMqExQQ8voyy1p' already exists.
RT @adamdriscoll: Just added some #UniversalAutomation documentation about pre-defined variables in UA jobs. ....
RT @adamdriscoll: #PowerShell #UniversalDashboard 2.8.2 is now available on the PowerShell Gallery. Lots of fixes, some improvements to Adm…
@psdevuk @adamdriscoll @psdbatools For context, this is a solution, but it's using standard 
bash
on Ubuntu:

export ApiKey="57647625454354365"
PS/home/thufir/powershell/helloPSTwitterAPI>
PS/home/thufir/powershell/helloPSTwitterAPI>/twitter.ps1
警告:具有AccessToken“17639841-ZLTXV9QW0ZLW60WNY2MTCAZ0FELJMQEXQ8VOYY1P”的OAuthSettings已存在。
RT@adamdriscoll:刚刚添加了一些关于UA作业中预定义变量的通用自动化文档。。。。
RT@adamdriscoll:#PowerShell#UniversalDashboard 2.8.2现已在PowerShell图库中提供。大量修复,对Adm的一些改进…

@psdevuk@adamdriscoll@psdbatools对于上下文,这是一个解决方案,但它在Ubuntu上使用标准的
bash

echo $ApiKey
要检查ApiKey是否设置正确,请执行以下操作:

但仍希望通过powershell实现这一目标:

PS /home/thufir/powershell/helloPSTwitterAPI> 
PS /home/thufir/powershell/helloPSTwitterAPI> ./twitter.ps1
WARNING: OAuthSettings with AccessToken '17639841-ZltXv9qW0zlW60WNy2MtcAZ0FEljMqExQQ8voyy1p' already exists.
RT @adamdriscoll: Just added some #UniversalAutomation documentation about pre-defined variables in UA jobs. ....
RT @adamdriscoll: #PowerShell #UniversalDashboard 2.8.2 is now available on the PowerShell Gallery. Lots of fixes, some improvements to Adm…
@psdevuk @adamdriscoll @psdbatools For context, this is a solution, but it's using standard 
bash
on Ubuntu:

export ApiKey="57647625454354365"

因为虽然我可以运行
pwsh twitter.ps1
,而且powershell将正确地拾取环境变量,但visual studio代码无法这样做。另见:


所以。。。powershell代码在哪里?您显示的似乎只是错误和输出…哦,对了,我不知道您现在可以在linux机器上运行powershell。我更习惯于另一种方式,在windows机器上运行bash脚本