I'd like to be able to put log messages in the middle of bash functions, without affecting the output of those very functions. For example, consider the following functions log()
and get_animals()
:
# print a log a message
log ()
{
echo "Log message: $1"
}
get_animals()
{
log "Fetching animals"
echo "cat dog mouse"
}
values=`get_animals`
echo $values
After which $values
contains the string "Log message: Fetching animals cat dog mouse"
.
How should I modify this script so that "Log message: Fetching animals"
is outputted to the terminal, and $values
contains "cat dog mouse"
?