title: How to get the content of a function in a string using bash?
body: <p>I have already searched about this particular problem, but couldn't find anything helpful.</p>
  
  <p>Let's assume I have following functions defined in my <code>~/.bashrc</code> (Note: this is pseudo-code!):</p>
  
  <pre><code>ANDROID_PLATFORM_ROOT="/home/simao/xos/src/"
  
  function getPlatformPath() {
    echo "$ANDROID_PLATFORM_ROOT"
  }
  
  function addCaf() {
    # Me doing stuff
    echo "blah/$(getPlatformPath)"
  }
  
  function addAosp() {
    # Me doing stuff
    echo "aosp/$(getPlatformPath)"
  }
  
  function addXos() {
    # Me doing stuff
    echo "xos/$(getPlatformPath)"
  }
  
  function addAllAll() {
    cd $(gettop)
    # repo forall -c "addCaf; addAosp; addXos" # Does not work!
    repo forall -c # Here is where I need all those commands
  }
  </code></pre>
  
  <p><strong>My problem:</strong></p>
  
  <p>I need to get the functions <code>addCaf</code>, <code>addAosp</code> and <code>addXos</code> in one single line.</p>
  
  <p>Like you can run following in bash (pseudo code):</p>
  
  <p><code>dothis; dothat; doanotherthing; trythis &amp;&amp; succeedsdothis || nosuccessdothis; blah</code></p>
  
  <p>I would like to run all commands inside the three functions <code>addCaf</code>, <code>addAosp</code> and <code>addXos</code> <strong>in just one line</strong>.</p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>What I already tried:</strong></p>
  
  <p><code>repo forall -c "bash -c \"source ~/.bashrc; addAllAll\""</code></p>
  
  <p>But that didn't work as well.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>To clarify what I mean.</p>
  
  <p>I want something like that as a result:</p>
  
  <pre><code>repo forall -c 'function getPlatformPath() { echo "$ANDROID_PLATFORM_ROOT"; }; ANDROID_PLATFORM_ROOT="/home/simao/xos/src/"; echo "blah/$(getPlatformPath)"; echo "aosp/$(getPlatformPath)"; echo "xos/$(getPlatformPath)"'
  </code></pre>
  
  <p>But I don't want to write that manually. Instead, I want to get those lines from the functions that already exist.</p>