【问题标题】:How do create a shell script to automate running watchcompile and browser-sync如何创建一个 shell 脚本来自动运行 watchcompile 和浏览器同步
【发布时间】:2015-02-16 13:45:09
【问题描述】:

我正在尝试执行类似的操作来自动执行 watchcompile 和浏览器同步,但它不起作用。

#!/bin/sh
nvm use 0.10
watchcompile
browser-sync start --server --files "index.html, css/*.css, js/*.js"

这将在项目目录中运行。

运行上面的代码给了我以下信息:

./watch.sh: line 2: nvm: command not found
./watch.sh: line 3: watchcompile: command not found
./watch.sh: line 4: browser-sync: command not found

watchcompile 和 browser-sync 应该是独立的进程。

任何帮助将不胜感激。

【问题讨论】:

    标签: scripting sh watch nvm browser-sync


    【解决方案1】:

    我就是这样解决的:

    我将此添加到 ~/.bash_profile。这会将 nvm 目录添加到 PATH:

    export PATH="~/.nvm/v0.10.33/bin/:$PATH"
    

    然后我将这些行添加到 watch.sh:

    #!/bin/bash
    watchcompile &
    ps -eaf | grep watchcompile
    cd htdocs
    browser-sync start --server --files "index.html, css/*.css, js/*.js" &
    ps -eaf | grep browser-sync
    

    第 2 行和第 5 行末尾的 & 使命令在后台运行,两个

    ps -eaf | grep command
    

    这些行只是为了给我后台进程的进程 ID,以便我以后可以杀死它们。

    我确信有更好的方法来做到这一点,但至少这是可行的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 2011-10-20
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      相关资源
      最近更新 更多