带后台进程的bash脚本

带后台进程的bash脚本,bash,background,jobs,Bash,Background,Jobs,我的脚本中包含以下内容: #!/bin/bash [ ! -S ./notify ] && find ./stylesheets/sass/ \-maxdepth 1 \-type f \-regex '.*/[^_][^/]*\.scss$' | entr \+notify & entr在此所做的是将notify创建为命名管道 [插入] while read F; do ... #some processing on

我的脚本中包含以下内容:

#!/bin/bash

[ ! -S ./notify ] && find ./stylesheets/sass/ \-maxdepth 1 \-type f \-regex '.*/[^_][^/]*\.scss$' | entr \+notify &
entr
在此所做的是将
notify
创建为命名管道

[插入]

while read F; do
            ...
            #some processing on found files 
            #(does not matter for this question at all)
            ...
done < notify

它可以工作,但我希望有一个更好的解决方案来检查
notify
fifo是否存在,因为有时可能需要超过1秒。

您可以随时轮询要创建的命名管道:

until [ -p notify ]; do read -t 0.1; done

如果您不需要在运行之间维护变量,您也可以考虑使用脚本而不是Enter的<代码> +通知< /代码>。这样可以避免问题。

这是如何工作的?我可以看到脚本运行时有
notify
,当我
CTRL-C
notify
文件就会消失。我是否应该在脚本的最开始将测试条件
-S
更改为
-p
-S
检查套接字,所以是的。我不知道你的
notify
管道是如何清理的。此代码对此不负责。今晚你帮了我两次,我欠你一杯啤酒:)
until [ -p notify ]; do read -t 0.1; done