2017-12-25 34 views
1

sarge 라이브러리로 쉘 스크립트를 실행하려고합니다. 내 파일 script.sh이 콘텐츠가 있습니다sarge로 쉘 스크립트를 실행하면 따옴표가 붙습니다.

#!/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') 

내가 더 inotifywait 프로세스가 실행되지 htop에 참조하십시오. 그러나 쉘에서 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 

답변

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입니다 '\'정의되지 않은,하지만 당신은
  3. 을 얻었다 "\\ n"은있다
  4. 만 실행 inotifywait -mr --exclude '(.git|.idea|node_modules)' 쉘에게는 충분하지 않습니다.
+0

당신의 직접'어쩌면'도움이되지 않았고, 1/2/3도 도움이되지 못했습니다 (왜냐하면 나는 다른 부분의 이스케이프 문자와 다음 줄 문자가 있기 때문에 작동합니다). 당신의 대답은 내가 조금 더 실험하고 받아 들일만한 결과를 얻는 것을 도왔다. '''inotifywait -mr --exclude "(.git | .idea | node_modules)"-e 수정, 생성, 삭제 $ {LOCAL_PROJECT_ROOT} - 당신이 보시다시피, 작은 따옴표를 큰 따옴표로 바꾸는 것은 첫 번째 경우에는 작동하지만 두 번째 따옴표에서는 작동하지 않습니다. 대신 큰 따옴표로 작은 따옴표를 감쌀 수 있습니다. 이상한,하지만 작품, 고마워요 :) – valignatev