This part:
my $bashcode=<<'__bash__';
. /opt/qip/etc/qiprc;
. /opt/sybase/sybase.sh
perl -mdata::dumper -e 'print dumper \%env';
__bash__
Is a here doc and you would do this in Python:
bashcode="""\
. /opt/qip/etc/qiprc;
. /opt/sybase/sybase.sh
perl -mdata::dumper -e 'print dumper \%env';
"""
You would shell out to Bash using something like os.system or subprocess.check_output.
The result of that is then fed to eval to be run as Perl code.
(The wisdom, and the result of the eval is dependant on what these Bash commands produce. It would appear that those commands are producing a Perl script. Obviously, that will not execute in Python. Python also has eval. Use eval in any language cautiously.)
The use of \%env in Perl would seem to indicate access to the environment of the host. However, the actual Perl variable to access the OS environment hash is ENV in uppercase. In Bash, you access the environment with a lowercase env
To access the host environment in Python, use os.environ
os.system("bash -c "+bashcode)?data::dumper. Justenvin the shell should give you the output you want. Whether you callbash -c "code"from Perl or Python should be immaterial; the only question is really why you are using either when clearly this is a Bash task. If the task is to import these variables to Python, perhaps look atshlex.envas the third line of the bash script) and use some pythony way to runbash -c ...and capture and parse the output.