bash export command in powershell

10,546

The description of the shell command is already in the document that you provide.

$ export $(grep -v '^#' .azure-env | xargs)

This uses grep to go through your .azure-env file excluding any lines that are comments, passing any values into xargs so they will be formatted to be interpreted by the shell. We then export these so they´re passed as environment variables to the commands we envoke.

And you can convert the shell command into PowerShell like this:

Get-Content .\azure.txt | Select-String -NotMatch "^#" | ForEach-Object { 
    $array= $_[0].ToString().split("=")
    [System.Environment]::SetEnvironmentVariable($array[0], $array[1])
    }

The screenshot of the result shows here:

enter image description here

Share:
10,546
Renm
Author by

Renm

Updated on June 11, 2022

Comments

  • Renm
    Renm almost 2 years

    I'm trying to follow this guide to test Django on Azure: https://github.com/carltongibson/rest-framework-tutorial/blob/master/docs/azure/2-appservice.md , however i'm stuck at running the following command since i'm doing it from PowerShell:

    $ export $(grep -v '^#' .azure-env | xargs)

    What would the command be in PowerShell and can someone explain what it does ?

    Thanks

  • Renm
    Renm over 5 years
    sorry for the late reply, couldn't reply back back right away due to a long travel. When I run the command I get the following error : Exception calling "SetEnvironmentVariable" with "2" argument(s): "String cannot be of zero length. Parameter name: variable" At line:3 char:5 + [System.Environment]::SetEnvironmentVariable($array[0], $array[1] ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~‌​~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentException
  • Charles Xu
    Charles Xu over 5 years
    You need to make sure the environment variables in the right format as me: key=vaule.