In the following code, I construct a variable $probe1 that I want to then pass to a bash script. I the toy example below, the output is blank, i.e. $probe1 is not recognized the the bash shell script within the os.system call. What needs to be done?
for line1 in datfile:
datmat=datmat+[line1.rstrip('\n').split('\t')]
probe=datmat[i][0]
snp1=datmat[i][2]
probe1='permprobes'+probe+'pheno.pphe'
os.system('echo $probe1')
Seems like this is what you are trying to do:
In [2]: os.environ['probe1'] = 'hello'
In [3]: os.system('echo $probe1')
hello
But I have no idea why you would like to do this ...
os.system('echo {0}'.format(probe1))
probe1 is a python variable, not a shell variable.
os.environ['probe1'] = probe1
will set the bash environment variable to the python variable contents. Once the python script exits though, the environment variable goes away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With