title: Create a directory in a function, then return path as a string to caller in Bash
body: <p>this is my first time posting here. I don't know if this has been already asked, but I can't find an answer anywhere.</p>
  
  <p>So, I'm trying to make a little script that creates a directory tree, using the root directory I pass as a parameter from the calling function, and then I want to return the full path to the caller function. Here's what I have so far:</p>
  
  <pre><code>#!/bin/bash
  function createLogPath(){
    local __BASE="$1/var/log"
    local __fullPath=$2
  
    mkdir -p $__BASE
  
    if [ $? -eq 0]
    then
      __fullPath=$( sed "$__BASE" )
      eval $__fullPath
    fi
  }
  </code></pre>
  
  <p>As you can possibly tell by my code, there are several things I still don't grasp about Bash, since I've been only working with it for like a week or something, so I'm doing this script for testing and learning purposes mostly. My intention with this little function is to create a path to store log files at a given location, and then return the full path to the caller function, so that I can use that path to create a log file in '<em>../var/log</em>'.</p>
  
  <p>But when I call this function from another script, like this:</p>
  
  <pre><code>#!/bin/bash
  . makedir.sh  # That's the name of the script where createLogPath() is
  
  BASE=$1
  RESULT=''
  
  createLogPath $BASE $RESULT
  
  printf "The path is: %s\n" $RESULT
  </code></pre>
  
  <p>This is not printing anything... what I'm trying to do is return the full path to '<em>../var/log</em>' as a string, but eval keeps treating $__fullPath as a directory and it's giving me a headache...</p>
  
  <p>As you can see from my code, I have no idea what I'm doing, so please explain what I'm doing wrong as well as the correct way to do what I'm trying to do. Any advice would be appreciated.</p>