2

Being new to PowerShell (I use the version 5.1 under Windows 10), I am not sure how to proceed with a simple Linux file which just sets lots of environment variables:

FOO=bar
BAR=123
...

Is there a quick PowerShell magic to set them under Windows from this fie or should I better opt for example to Python to convert this file to

set FOO bar
set BAR 123
...

P.S. manual maintenance of a Windows version of the file is not an option in this context.

1
  • 2
    Sorry, we need more context. So you have a Linux file which sets env variables. You want to use PowerShell on Windows to set the same variables. Why do you need the variables? And if you want to run a Linux script under Windows, why don't you just install a Linux/Unix shell under Windows (e.g. from Cygwin)? What do you want to accomplish?
    – sleske
    Jul 19, 2017 at 18:24

1 Answer 1

4

It*s IMO pointless to stuff the var=value pairs into the environment (unless using it in a sub process). If the pairs are to be used with powershell you could read them as a csv with delimiter =

> $linuxfile = import-csv .\linuxfile.txt -Delimiter '=' -Header Var,Value
> $linuxfile

Var Value
--- -----
FOO bar
BAR 123

Not the answer you're looking for? Browse other questions tagged or ask your own question.