idioms for returning multiple values in shell scripting

后端 未结 10 908
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 20:56

Are there any idioms for returning multiple values from a bash function within a script?

http://tldp.org/LDP/abs/html/assortedtips.html describes how to echo multipl

10条回答
  •  自闭症患者
    2020-12-29 21:42

    Yet another way:

    function get_tuple()
    {
      echo -e "Value1\nValue2"
    }
    
    IFS=$'\n' read -d '' -ra VALUES < <(get_tuple)
    echo "${VALUES[0]}" # Value1
    echo "${VALUES[1]}" # Value2
    

提交回复
热议问题