1

In a bash script, if I have a variable $FOO which equals "BAR", how would I set the environment variable named BAR equal to "BAZ"? Thanks.

David
  • 485
  • 1
  • 5
  • 16
  • 1
    Maybe `export BAR="BAZ"`? – eeijlar May 15 '18 at 22:11
  • Evidently it's simply $FOO=BAZ but it wasn't working for me because my variable was an array entry. I'll get the array entry value into a scalar and then I should be good. Thanks. – David May 15 '18 at 22:16
  • with simpy $FOO=BAZ got: BAR=BAZ: command not found. ` export $FOO=BAZ ` did the job, though it also exports. – Nikolay Sep 17 '20 at 18:10

1 Answers1

1

export $(echo "$(echo $FOO)=BAZ") should work. I'm using bash --version = 4.1.2 with success.

export FOO=BAR
export $(echo "$(echo $FOO)=BAZ")
echo $BAR

BAZ

Tom D
  • 21
  • 4