Hi,
I need to retrun multiple values
function errorFileCreation
{
echo "Before"
return -1 "Siva";
echo "Aftyer"
}
echo ${?} - This can be used to getting first value.
how can i get second one.
Advance Thanks...
Shiv
Hi,
I need to retrun multiple values
function errorFileCreation
{
echo "Before"
return -1 "Siva";
echo "Aftyer"
}
echo ${?} - This can be used to getting first value.
how can i get second one.
Advance Thanks...
Shiv
In shell scripting, there is no concept of return value of a function. You can just set the value in some variable and can use it later.
E.g.
...
code
...
function name{
echo "123"
retVal="abc"
echo "123"
}
...
code
...
main{
...
code
name
echo $retVal
...
}
main
Thanks it is working fine...
Another way is to echo the return value and get it with process substitution
Note the echo redirected to stderr : >&2
function errorFileCreation()
{
echo "Before" >&2
echo -1 Siva
echo "Aftyer" >&2
}
ReturnArray=( $(errorFileCreation) )
# to see the returned values
for i in ${!ReturnArray[@]}; do
echo "$i ${ReturnArray[$i]}"
done