簡體   English   中英

用 sarge 運行 shell 腳本會吃掉我的報價

[英]Running shell script with sarge eats my quotes

我正在嘗試使用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"
  1. 轉義字符未定義 '\\'檢查這個
  2. 下一行字符是\\n ,但你得到了 "\\\\n"
  3. 你只運行inotifywait -mr --exclude '(.git|.idea|node_modules)'這對 Shell 來說是不夠的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM