Executing generated commands in bash
I want to run a series of bash commands generated by a Python script. The commands are of the form export foo="bar" and alias foo=bar. They must modify the environment of the current process.
This works great:
until an export command contains a space e.g. export x="a b". This generates an error, and only "a is exported (quotes included).
Currently I'm working around this by outputting generate_commands to a temporary file and sourcing that, but is there a more elegant solution?
./generate_commands | bash
This will pipe the output of the script as input to bash
To allow for variables to be visible in the current shell, you need to source the output: