Both commands are executed in different subshells.
Setting variables in the first system
call does not affect the second system
call.
You need to put two command in one string (combining them with ;
).
>>> import os
>>> os.system('GREPDB="echo 123"; /bin/bash -c "$GREPDB"')
123
0
NOTE You need to use "$GREPDB"
instead of '$GREPDBS'
. Otherwise it is interpreted literally instead of being expanded.
If you can use subprocess
:
>>> import subprocess
>>> subprocess.call('/bin/bash -c "$GREPDB"', shell=True,
... env={'GREPDB': 'echo 123'})
123
0