Let's say i have a bash function that i source into a shell.
# cat sample.sh
function func()
{
echo "Custom env : $CUSTOM_ENV"
}
Now i source this script in the bash shell:
#source sample.sh
Then i define:
export CUSTOM_ENV="abc"
and then call func() from bash shell, it displays:
#func
Custom env : abc
Now if i am calling a python script from the same shell, i want to invoke the function func() from the python script. Anyway to achieve this ?
What i tried:
- Tried os.system('func') - Doesn't work
- Tried subprocess.check_output('func', shell=True, env=os.environ.copy()) - Doesn't work
Any guidance ?