我正在嘗試編寫一個Shell腳本(用於Mac OSX Termninal),它將運行一條命令來啓動一個開發服務器(gulp serve)。我有它的工作,除了服務器連續運行,所以它不允許我在同一窗口中輸入後續命令而不停止服務器(Control + C)。我的問題是,有沒有一種方法可以在後臺運行進程和/或禁止任何/所有輸出?我的目標是寫一個'停止服務器'命令,將會終止進程(我也不確定該怎麼做)。我已經嘗試了使用&符號和/ dev/null的所有組合,並且沒有什麼效果。這是我到目前爲止有:如何在後臺運行shell命令並禁止所有輸出?
if [ "$1" = "server" ]
then
if [ "$2" = "on" ]
then
cd/& gulp serve --gulpfile /server/example/gulpfile.js # the output is still shown
printf "\033[0;32mserver is online.\033[0m\n"
else
killall tail &>/dev/null 2>&1 # this doesn't kill the process
printf "\033[0;32mportals is offline.\033[0m\n"
fi
fi
這樣做的竅門,謝謝你的回答和詳細的解釋!感謝@Diego Torres Milano! – robmarston