Python调用shell脚本 - 没有目录?

cem*_*ate 0 python bash subprocess find

在python脚本中,我调用bash脚本如下:

subprocess.Popen(["./scan.sh", dir])
Run Code Online (Sandbox Code Playgroud)

在那个剧本里面,有,

find $1 -name "*013*.txt" > found_files.txt
Run Code Online (Sandbox Code Playgroud)

出于某种原因,python中的dir参数被转换为bash脚本中带引号的版本.在python中打印'dir'会产生用户输入的确切路径:

~/Desktop/Files
Run Code Online (Sandbox Code Playgroud)

但是,找不到了

find: '~/Desktop/Files' no such directory
Run Code Online (Sandbox Code Playgroud)

使用〜/ Desktop/Files手动运行scan.sh可以正常工作.为什么要引用它?...?

Ign*_*ams 8

没有.发生的事情是~没有被解释,因为这是shell的工作.用于os.path.expanduser()在传递路径之前展开路径subprocess.