How to set environment variables for bash from within powershell

0 votes

Using powershell how do I set the environment variables (here, particularly "ApiSecret") so that printenv will show the necessary variables?

(Operating on the assumption that the problem is that Visual Studio and bash aren't picking up the environment variables properly. They can be set from bash easily enough.)

I'm on 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 code:

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 Code:

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> 

but then neither is the standard bash console:

bash console:

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 console, but within 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 👀
@adamdriscoll 🔥
@BillKindle @McDonalds @Wendys Sad, but that’s what I’m going to do next time. It should be ‘BigMac with Bacon Bits… ....
I was excited to try out the new BigMac with Bacon... but horrible portion.. looks like cesar salad bacon bits...… ....
@WindosNZ PSTwitterAPI? ;)
@Marioperator Thanks for the shoutout ❤️
RT @adamdriscoll: Nice! Financial charts for UD! ...U #powershell h...
@TomatoApp1 Constantly having to bind/unbind MiaoMiao device. And now the app won’t even open after trying reinstal… ...
@adamdriscoll It shall get indexed and searchable in 15 minutes! I can just imagine your amazon shopping suggestions...
@adamdriscoll @LeeAlanBerg Pics or it didn’t happen
@SwiftOnSecurity @adbertram Did you end up finding a more elegant solution?
RT @racheldianeb: Had cake and wine tonight. 2 things I said I wouldn’t consume in Jan and would generally limit in 2020. It’s Jan 1st. So…
@adilio @sstranger Someone would probably be wrong.. 😝
@AndrewPlaTech @sstranger You have nothing to lose.. I mean, clearly I lost.. ;)
Someone’s mother has four sons. North, South and East. What is the name of the fourth son. Private message me the n… ...:,...
RT @_youhadonejob1: Let's all take a moment to recognize this man, who was instrumental in thwarting the Nakatomi Plaza terrorist attacks o…
RT @EssentialSign_: For whoever needs this this evening. ...
RT @wongmjane: I'm working on something new on my website, check it out and lemme know what you think :D

http://localhost:3000
done
PS /home/thufir/powershell/helloPSTwitterAPI> 

(From bash, printenv doesn't show the API keys which the script depends upon.)

Version: 1.41.1 Commit: 26076a4de974ead31f97692a0d32f90d735645c0 Date: 2019-12-18T15:04:31.999Z Electron: 6.1.5 Chrome: 76.0.3809.146 Node.js: 12.4.0 V8: 7.6.303.31-electron.0 OS: Linux x64 4.18.0-25-generic snap

Jun 3, 2022 in Linux Administration by Rahul
• 3,380 points
792 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

0 votes
1 answer

How to take input from user in bash script?

You can use if-else branch to check ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 69,220 points
1,118 views
0 votes
1 answer

How to find the first field from a file in Bash Shell?

Hi@akhtar, You can extract text from a file. ...READ MORE

answered Oct 20, 2020 in Linux Administration by MD
• 95,460 points
1,058 views
0 votes
0 answers
0 votes
0 answers

How to send control+c from a bash script?

I'm starting a number of screens in ...READ MORE

Jun 16, 2022 in Linux Administration by Rahul
• 3,380 points
745 views
0 votes
0 answers

How can I get the directory where a Bash script is located from within the script itself?

How do I get the path of ...READ MORE

Jun 21, 2022 in Linux Administration by Korak
• 5,820 points
441 views
0 votes
0 answers

How to detect the OS from a Bash script?

I would like to keep my .bashrc and .bash_login files in ...READ MORE

Jun 21, 2022 in Linux Administration by Korak
• 5,820 points
533 views
0 votes
0 answers

How to detect the OS from a Bash script?

I would like to keep my .bashrc and .bash_login files in ...READ MORE

Jun 22, 2022 in Linux Administration by Korak
• 5,820 points
558 views
0 votes
0 answers

How to execute mongodb commands from bash shell?

I searched and found that one can ...READ MORE

Jun 22, 2022 in Linux Administration by Korak
• 5,820 points
2,419 views
0 votes
1 answer
–1 vote
1 answer

How to use help command for ls?

The help command is limited and it ...READ MORE

answered Jan 3, 2019 in Linux Administration by Omkar
• 69,220 points
3,384 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP