Call a function using nohup

前端 未结 6 1701
滥情空心
滥情空心 2020-12-10 10:59

I am trying to call a function using nohup like this:

function1(){
    while true 
    do
        echo \"function1\"
        sleep 1
    done
}
         


        
6条回答
  •  囚心锁ツ
    2020-12-10 11:38

    Yes ! It is possible however tricky, and strictly bash > v2 compatible :

    function1(){ local msg=${*:-function1}; echo msg=$msg; }
    nohup -- sh -c "$(typeset -f function1); function1 MESSAGE" >nohup.log 2>&1 0

    And don't forget "typeset" is bash deprecated in favor of "declare" (though I don't entirely agree with this).

提交回复
热议问题