Returning value from called function in a shell script

后端 未结 5 520
自闭症患者
自闭症患者 2020-11-27 08:55

I want to return the value from a function called in a shell script. Perhaps I am missing the syntax. I tried using the global variables. But that is also not working. The c

5条回答
  •  Happy的楠姐
    2020-11-27 09:33

    In case you have some parameters to pass to a function and want a value in return. Here I am passing "12345" as an argument to a function and after processing returning variable XYZ which will be assigned to VALUE

    #!/bin/bash
    getValue()
    {
        ABC=$1
        XYZ="something"$ABC
        echo $XYZ
    }
    
    
    VALUE=$( getValue "12345" )
    echo $VALUE
    

    Output:

    something12345
    

提交回复
热议问题