Doesn't sh support process substitution <(…)?

前端 未结 3 2000
北荒
北荒 2020-12-07 02:55

On a Centos 6 machine, this works:

bash -c \'if grep -qP --line-buffered \".+\" <(tail -n 1000 -F catalina.out) ; then echo \"yes\"; fi\'
<
3条回答
  •  独厮守ぢ
    2020-12-07 03:14

    The syntax <(...) is only supported by BASH.

    For any POSIX shell, use this approach:

    sh -c 'tail -n 1000 -F catalina.out | if grep -qP --line-buffered ".+" ; then ...'
    

    i.e. move the stdin redirection in front of the if with a pipe. The if will pass stdin on to the grep.

    if tail ...| grep won't work since the if won't be able to see it's then/fi because the pipe separates processes.

提交回复
热议问题