0

I have a shell script containing a single command

sudo my_command | parse_to_exports_cmd

when I run this script I get the following on stdout

export MY_VAR_A=abcdef123
export MY_VAR_B=qwerty123

How would I modify my script to actually set these environment variables within the parent shell?

stevejpurves
  • 101
  • 1

1 Answers1

1

You can wrap the output in eval. This should not be run lightly because it executes any output in the context of your calling shell. You must trust the output.

eval $(sudo my_command | parse_to_exports_cmd)
roaima
  • 1,591
  • 14
  • 28