与中士一起运行shell脚本会吃掉我的引用

2024-09-22 16:40:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用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.run('sh script.sh')

我看到htop没有运行inotifywait进程。 但是,当我在shell中直接用sh script.sh运行这个脚本时,一切都按预期工作。你知道吗

如果我删除--exclude--format两个都包含引用参数的部分,sarge也可以运行。你知道吗

如果我把剧本改写成这样的话,中士也会觉得不错的:

echo "inotifywait -mr --exclude '(.git|.idea|node_modules)' -e modify,create,delete ${LOCAL_PROJECT_ROOT} --format '%w%f'" | /bin/sh

Tags: gitproject脚本formatbinlocalshscript
1条回答
网友
1楼 · 发布于 2024-09-22 16:40:12

听起来像是模块问题。你知道吗

因为:

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)' 这对壳牌来说还不够。你知道吗

相关问题 更多 >