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:

$(./generate_commands.py)

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?

Answers


./generate_commands | bash

This will pipe the output of the script as input to bash

Edit:

To allow for variables to be visible in the current shell, you need to source the output:

source <(./generate_commands)

or

. <(./generate_commands)

Need Your Help

facebook sdk question regarding dialog feed iphone

ios4 facebook

I use this code to post in facebook from my app in iphone

Count column values sort by occurence

php mysql sql select

I have a column in my table users that's called user_model. It contains different reoccurring names as, value1 value2 value3 etc.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.