How can I assign the output of a function to a variable using bash?

前端 未结 3 1729
小蘑菇
小蘑菇 2020-12-23 09:06

I have a bash function that produces some output:

function scan {
  echo \"output\"
}

How can I assign this output to a variable?

3条回答
  •  悲&欢浪女
    2020-12-23 09:43

    I think init_js should use declare instead of local!

    function scan3() {
        declare -n outvar=$1    # -n makes it a nameref.
        local nl=$'\x0a'
        outvar="output${nl}${nl}"  # two total. quotes preserve newlines
    }
    

提交回复
热议问题