Execute a shell function with timeout

前端 未结 10 1127
死守一世寂寞
死守一世寂寞 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:06

    function foo(){
        for i in {1..100};
        do 
            echo $i;  
            sleep 1;
        done;
    }
    
    cat <( foo ) # Will work 
    timeout 3 cat <( foo ) # Will Work 
    timeout 3 cat <( foo ) | sort # Wont work, As sort will fail 
    cat <( timeout 3 cat <( foo ) ) | sort -r # Will Work 
    

提交回复
热议问题