2012-09-11 3 views
4

내가 특별히 동시에 2 개 하위 디렉토리에 2 개 개의 다른 파일 형식을 볼려고 수정 다음 'JS'하위 디렉토리에inotifywait를 파일 유형에 따라 명령을 실행하려면

    .coffee 파일 형식
    .styl 파일 형식 'CSS'하위 디렉토리에

는 난 단지 너무 많은 떠들썩한 파티를 알고 난

while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do 
    # regex pattern to match the file ending 
    # and define it to $ending 

    if[ $ending == coffee ] 
    then 
    coffee -c $file 
    elif[ $ending == styl ] 
    then 
    stylus -c $file 
    fi 
done 
,369를 작동하려면 이렇게 뭔가를 얻으려고



// 편집 // 이 줄을 수정 :

while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do 

그래서 지금은 모두 파일을 검사하지만, JS에는 CSS의 폴더에 .coffee 파일 또는 .styl 파일이 존재하지 않는 경우는, 그것이를 반환 파일을 찾을 수 없습니다.

는 또한 나는이 스크립트를 실행할 때, 그것은 반환/다음 3 회

Setting up watches. 
Watches established. 
./css/styles.styl 
+0

inotifywait는 POSIX 확장 정규 표현식을 사용하며 제한적입니다 : http://stackoverflow.com/questions/7943528/inotifywait-exclude-regex-pattern-formatti ng이 스크립트들을 분리하십시오. 하나는 커피/js 당 하나는 하나의 스타일/css 당 하나입니다. –

답변

2

하지 깨끗한 솔루션을 실행하지만 당신은 더 나은 솔루션이있는 경우

#!/bin/sh 

while file=$(inotifywait -r -e modify --format "%w%f" ./); do 
    EXT=${file##*.} 
    if [ $EXT = "styl" ] 
    then 
    stylus -c $file 
    fi 
    if [ $EXT = "coffee" ] 
    then 
    coffee -c $file 
    fi 
done 

작동 눈치 만 시계 내가 원하는 파일, 그때 나는 모두 귀입니다

관련 문제