Execute a shell function with timeout

前端 未结 10 1118
死守一世寂寞
死守一世寂寞 2020-12-01 00:40

Why would this work

timeout 10s echo \"foo bar\" # foo bar

but this wouldn\'t

function echoFooBar {
  echo \"foo bar\"
}

e         


        
10条回答
  •  再見小時候
    2020-12-01 01:16

    As Douglas Leeder said you need a separate process for timeout to signal to. Workaround by exporting function to subshells and running subshell manually.

    export -f echoFooBar
    timeout 10s bash -c echoFooBar
    

提交回复
热议问题