Suppose you have a bunch of commands as would be typed into a shell
export x=1
cd foo/the\ bar/baz
grep x y z
cd "the/quoted path"
ls -l
To run a single command you can do:
subprocess.run(['ls','l'])
But the commands aren't independent. Later commands depend on earlier commands, exported variables, etc. What is the pythonic way to run these commands as if these were lines of code in a shell script? Is there a way around using the shell=True "taboo"?
# DOESN'T work, each run is independent:
for c in cmds:
subprocess.run(c, shell=True)
# Seems to work but is mashing everything into a giant string the best way?
subprocess.run(';'.join(cmds), shell=True)