Define function in unix/linux command line (e.g. BASH)

后端 未结 5 1339
时光说笑
时光说笑 2021-01-04 00:21

Sometimes I have a one-liner that I am repeating many times for a particular task, but will likely never use again in the exact same form. It includes a file name that I am

5条回答
  •  忘掉有多难
    2021-01-04 00:52

    The easiest way maybe is echoing what you want to get back.

    function myfunc()
    {
        local  myresult='some value'
        echo "$myresult"
    }
    
    result=$(myfunc)   # or result=`myfunc`
    echo $result
    

    Anyway here you can find a good how-to for more advanced purposes

提交回复
热议问题