Running echo $HISTFILE in bash gives me /home/myname/.bash_history.
Now I'm trying to use Python to access this HISTFILE shell variable by doing the following:
import subprocess
x = subprocess.check_output('echo $HISTFILE', shell=True)
print(x)
However, this gives me a blank output.
- If
subprocess.check_outputalong withshell=Trueexecutes the command in a shell, why doesn't it have a HISTFILE variable that I can access? - How can I work my way around this?
os.environ["HISTFILE"].$HISTFILElooks like any other environment variable but in reality it's a shell variable and you've to export it in order to access it usingos.environor child processes.