我正在尝试使用sarge库执行shell脚本。我的文件script.sh
有这个内容:
#!/usr/bin/env sh
export LOCAL_PROJECT_ROOT=/path/to/the/dir
inotifywait -mr --exclude '(.git|.idea|node_modules)' \
-e modify,create,delete ${LOCAL_PROJECT_ROOT} --format '%w%f'
我和sarge一样运行它:
sarge.run('sh script.sh')
我看到htop
没有运行inotifywait
进程。但是,当我使用sh script.sh
直接在shell中运行此脚本时,一切都按预期工作。
如果我删除包含引用参数的--exclude
和--format
部分,sarge也运行良好。
如果我将脚本重写为这样的话,它也可以运行sarge:
echo "inotifywait -mr --exclude '(.git|.idea|node_modules)' -e modify,create,delete ${LOCAL_PROJECT_ROOT} --format '%w%f'" | /bin/sh
听起来像模块问题。
因为:
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
[GCC 4.8.4] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> 'a' == "a"
True
>>> '%s' %"'a'"
"'a'"
>>> "%s" %'"a"'
'"a"'
>>>
也许 :
#!/usr/bin/env sh
export LOCAL_PROJECT_ROOT=/path/to/the/dir
inotifywait -mr --exclude "(.git|.idea|node_modules)" -e modify,create,delete ${LOCAL_PROJECT_ROOT} --format "%w%f"
\n
,但你有“\\ n”inotifywait -mr --exclude '(.git|.idea|node_modules)'
这对壳牌来说还不够。