How to return a values from a method which prints its out put [closed]

I have a method which prints its content with ‘printf’. I want the printed contents to be return.

parse_yml() {
   #some logics here
         printf("%s%s is %s", $1, code, $2, $3);

In above code, “printf("%s%s is %s", $1, code, $2, $3);” prints the desired values. But I need to return all printed values concatenated so that the a variable which is outside the method can have final all values into a single variable. Something like below:


I tried with defining a global variable called r, and instead of printf line:


and outside, when echoed, it was empty.

Any suggestion please how to return all values from that method ?


I don’t know, whether I understood you right, but in bash, you grab output like this:



echo $allContent

should then reveal the same, like

parse_yml. > parse_yml.out
cat parse_yml.out

The filename parse_yml. looks a bit suspicious – no file ending? And usually, you have to either specify the absolute path, or the relative path, which would be


except, if the current directory is in the PATH.

Leave a Reply

Your email address will not be published. Required fields are marked *