使用sarge运行shell脚本会吃掉我的引号

问题描述 投票:1回答:1

我正在尝试使用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 linux shell subprocess sh
1个回答
1
投票

听起来像模块问题。

因为:

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"
  1. 转义字符未定义'\'check this
  2. 下一行字符是\n,但你有“\\ n”
  3. 你只运行inotifywait -mr --exclude '(.git|.idea|node_modules)'这对壳牌来说还不够。
© www.soinside.com 2019 - 2024. All rights reserved.