0

Suppose I source the function myfunction defined by

myfunction(){
    myinnerfunction 
}

where myinnerfunction is defined as

myinnerfunction(){
    echo word
}

I'd like to find an equivalent of declare -f myfunction that displays the content of the inner function myinnerfunction, i. e.

myfunction ()
{
    echo word
}

instead of

myfunction ()
{
    myinnerfunction
}

Now, what if I have inner aliases instead of inner functions?

5
  • If this question was on stackoverflow it would be a duplicate. stackoverflow.com/questions/8426077/…
    – Elder Geek
    Sep 15, 2016 at 21:57
  • My question is "how to unfold the function with inner functions in it?"
    – user123456
    Sep 17, 2016 at 5:17
  • Can you edit your question to define your use of the term "unfold" and express how it's different from the question I linked? Thank you for helping us help you!
    – Elder Geek
    Sep 17, 2016 at 12:53
  • 1
    I don't think it's possible to do what you're asking. You'll just have to run declare -f for the inner function. To explain, Bash treats functions just like any other command; e.g. you could unset -f myinnerfunction then put a script myinnerfunction in your PATH and it would work exactly the same.
    – wjandrea
    Sep 17, 2016 at 15:22
  • I concur with @wjandrea. To achieve that feat, Bash may only bind command names to function references at the time of execution. Sep 17, 2016 at 15:28

1 Answer 1

0

Here is a short script that searches for inner function and define them at the same time (1 depth level only)

function declare-recursively () {
    declare -f $@
    declare -f | grep ' () {' | sed 's/ () {//' | while read i
    do
        declare -f $@ | grep -Po "[\t, ]$i " | while read j
        do
            declare -f $j
        done
    done
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .