我正在尝试使用 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"
- 转义字符未定义 '\' check this
- 下一行字符是
\n
,但你得到的是“\\n” - 你只运行
inotifywait -mr --exclude '(.git|.idea|node_modules)'
这对 shell 牌来说还不够。
关于python - 用 sarge 运行 shell 脚本会吃掉我的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47967211/