0

Please help me with the below functionality. I need to pass a function in the form of an argument to another function. In the second function one of the parameter has space in the string.

function funct_1
{       
        echo $1
        echo $2
        ${3}
}

function funct_2
{
    echo $1
    echo $2
    echo $3
}

funct_1 first second 'funct_2 first second "first second"'

Expected Result -

first 
second
first
second
first second
Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93

1 Answers1

1

Try eval:

function funct_1
{
        echo $1
        echo $2
        eval ${3}
}

function funct_2
{
    echo $1
    echo $2
    echo $3
}

funct_1 first second 'funct_2 first second "first second"'
Luis de Arquer
  • 377
  • 2
  • 8
  • Perfectly worked. Thanks for the quick answer. With the -x option I did understand what was actually happening and eval did the trick. Thanks again – Pulakesh Dev Das Oct 24 '16 at 02:57