I would use a temporary file to store the complex function result, and then read the value from the temp file for processing.
# Create a temp file for storage
tmppath=$(mktemp)
# run the command and get the output to the temp file
complex_command > ${tmppath}
# read the file into variable
message=$(cat "${tmppath}")
# use the variable
echo "$message"
rm -f ${tmppath}
# Create a temp file for storage
tmppath=$(mktemp)
# run the command and get the output to the temp file
complex_command > "${tmppath}"
# read the file into variable
message=$(cat "${tmppath}")
# use the variable
echo "$message"
rm -f "${tmppath}"
The usage of mktemp can refer to How create a temporary file in shell script?