0

I am using the below line to read an environment variable from my Kotlin code.

val accountPasswords = System.getProperty("AccountPasswords")

I have stored this environment variable in my Mac OS machine in ~/.bash_profile, in the below shown way.

export AccountPasswords=myPassword

When I print this accountPasswords variable I get {$AccountPasswords} instead of the real value. I went on to print the properties and below is how I get it.

key: AccountPasswords value: {$AccountPasswords}

How can I print the actual value? What am I doing wrong here? This works fine when I run it in a Linux machine. Any advice would be much appreciated.

AnOldSoul
  • 4,017
  • 12
  • 57
  • 118
  • I think that you have export AccountPasswords={$AccountPasswords} – Antoniossss Feb 08 '19 at 11:13
  • 2
    probably, you're confused by `System.getProperties()` and `System.getenv()` methods. [Java system properties and environment variables](https://stackoverflow.com/questions/7054972/java-system-properties-and-environment-variables) – Sergii Lagutin Feb 08 '19 at 11:14
  • 1
    @SergeyLagutin But System.getProperties seem to work fine in fetching Linux env variables? :( – AnOldSoul Feb 08 '19 at 11:55
  • @Antoniossss no I have the real value. The export statement I have put in the question is the exact same thing from my bash profile – AnOldSoul Feb 08 '19 at 11:56
  • @SergeyLagutin but then why do he get ANY value? – Antoniossss Feb 08 '19 at 12:34
  • @Antoniossss interesting question. probably he overrides the property in other places – Sergii Lagutin Feb 08 '19 at 12:37
  • @SergeyLagutin Then that would be the reason, not using "wrong set" i think. – Antoniossss Feb 08 '19 at 12:45
  • Besides, if you quick test like `System.getProperties().entrySet().forEach(e -> { System.out.println(e.getKey() + " -> " + e.getValue()); })` You will se it contains envs as well (as default values). At least prints every env on my side. – Antoniossss Feb 08 '19 at 12:48

0 Answers0