Other answers provide a way to do exactly what you ask, but I think the idea is a little crazy. There, an easier way to satisfy both scenarios is to move these variables to the configuration file. You can even save a simple assignment format.
Create your own config: (ini-style)
dt="01/03/16-01/09/16" cust_id="12345"
In python:
config_vars = {} with open('the/file/path', 'r') as f: for line in f: if '=' in line: k,v = line.split('=', 1) config_vars[k] = v week_date = config_vars['dt'] cust_id = config_vars['cust_id']
In bash:
source "the/file/path"
And you no longer need to do crazy parsing. Alternatively, you can simply use json for the configuration file, and then use the json module in python and jq in the shell for parsing.
source share