5

我特别想在 2 个子目录中同时查看 2 个不同的文件类型:

  'js' 子目录
  中的 .coffee 文件类型 'css' 子目录中的 .styl 文件类型

我只知道这么多 bash,我正试图让这样的东西发挥作用

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



// 编辑 // 修改了这一行:

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

所以现在它会检查这两个文件,但如果 css 文件夹中没有 .coffee 文件,或者 js 中没有 .styl 文件,它会返回未找到文件的错误。

另外我注意到当我运行这个脚本时,它返回/运行以下 3 次

Setting up watches.
Watches established.
./css/styles.styl
4

1 回答 1

3

不是最干净的解决方案,但有效

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

如果您有更好的解决方案,只观看我想要的文件,那么我全神贯注

于 2012-09-11T17:32:38.120 回答