Redirect function output to printf state ment seems not working in bash

bash, function, linux, printf

Solution

You need to actually call that function. Right now you're just passing a piece of text.

Try this:

printf "message :: %s %s\n" "$(display_output_message $1 $2)" "received"

Problem

Have created simple bash script as follows ``` #!/bin/bash declare -a message_list=("ok" "error" "cancel") display_output_message() { message_index=$1 message_type=$2 if [ $message_index -gt 2 ] then printf "Invalid Message index\n" exit 0 fi if [ $message_type -eq 1 ] then printf "%s\n" $message_index else printf "%s\n" "${message_list[$message_index]}" fi } printf "message :: %s %s\n" "display_output_message $1 $2" "received" ``` From above scripts i want to call `display_output_message()` function from `printf` and print the output of that function in `printf` statement from which it called. I have no idea how to redirect function out put to `printf`. So far what i have tried is shown above script and when i run script then is show me output as follows ``` $ ./script.bash 1 2 message :: display_output_message 1 2 received ``` So `printf` just print the name of function which i want to call and argument list but i want output as follows ``` $ ./script.bash 1 2 message :: ok received ``` I missed something minor or might be not knowlegde of how redirect output to `printf` . Have any one idea how can i solve it.?

Original source