passing variables from python to bash

A forum for general discussion of the Python programming language.

passing variables from python to bash

Postby corvi » Sun Sep 08, 2013 8:26 am

I am completely new to python and its syntax..
I have a bash-script which includes a python part in this way:
.. some instructions to get p, q, ... (floating numbers obtained through "awk" call to a datafile)
python >>END
... some calculations using previous bash results (p, q, ..)
a = ..
b = ..
... some analysis using python results(a, b, ..)
While I am able to pass bash outputs p, q to python simply through $p, $q, ..,
I did not find the way to pass python outputs a, b, .. to the following bash session.
How to do?
Posts: 4
Joined: Sun Sep 08, 2013 7:40 am

Re: passing variables from python to bash

Postby Somelauw » Sun Sep 08, 2013 8:40 pm

Here are a few ways I can think of:

Code: Select all
$ a=$(python<<END
$ echo $a

But that only works for a single variable.

You can make it work with multiple variables by using mapfile: ... -not-space

The other way is to execute bash from within python
Code: Select all["ls", "-l"])

I advise you to write your script as much as possible using only a single language, though.
Join the #python-forum IRC channel on!
Posts: 82
Joined: Tue Feb 12, 2013 8:30 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests