I have the following python code which tries to copy a file stored in a variable file
from a variable directory dir
. I also attempting get those variables passed as shell variables, then I can copy using shell command as well.
Is any/both of these possible? Then please amend my code.
import os
import shutil
import subprocess
dir='somedir'
file='somefile'
# Now I want to get $dir as a shell variable and copy the file to
# my present directory
os.system("echo $dir")
os.system("cp $dir/$file .")
# I want to copy dir/file to the present directory
shutil.copy(dir/file,file) # Following shutil.copy(src,dest) format
shutil.copyfile(dir/file,file)
The