Bash function not returning value to the script while running through cron
<p>I have a main script that calls a function , which is written in another file.I have sourced this file inside the main script. When I run this main script using cron, then the function does not return any value. Whereas if i run the same main script in console , the function returns value and prints on console.</p>

<p>Below is my main script.</p>

<pre><code>source /home/employee/conf/myConf.cfg $0
load_dte=`fnGetDate dir1 dir2/*`
fnLog "load_dte $load_dte"
</code></pre>

<p>And configuration file that contains the function:</p>

<pre><code>function fnGetDate(){
x="2016-06-21"
echo "$x"
}
</code></pre>

<p>When  this main script is scheduled via cron :
Output is :</p>

<p><code>load_dte</code></p>

<p>Whithout cron output:</p>

<p><code>load_dte 2016-06-21</code></p>

<p>Any help is appreciated.</p>

<p>Edit: 
Below is the full codebase:</p>

<p>$1 $2 are the hdfs locations/tmp/hdfs/loc1 and /tmp/hdfs/loc2
main script:</p>

<pre><code>#/bin/bash
PATH=/bin:/usr/bin

       dirname=$( cd "$( dirname "$0" )" &amp;&amp; pwd )
    source `echo ${dirname%/*}`/conf/lib.cfg $
        fnGetScriptPath $0
        fnCreateLogFile ${0}
        fnMain(){
                TBL_BUS="$1"
                TBL_ENT="$2"
                load_dte=fnGetDate "/tmp/hdfs/loc1" "/tmp/hdfs/loc2*" ""
                echo load_dte $load_dte
                fnLog "load_dte $load_dte" "$C_INFO"
        }
                fnMain $1 $2
</code></pre>

<p>Below is the config file:</p>

<pre><code>SCRIPT_NAME="$1"
CURRENT_DATE=`date +%Y-%m-%d`

C_INFO=0
C_SUCCESS=1
C_DEBUG=2
C_WARN=3
C_ERROR=4
LOG_STATUS=(INFO SUCCESS DEBUG WARN ERROR)
function fnCreateLogFile(){
        fnGetScriptPath $1
        FILE=`basename $1`
        LOGDIR=$root_dir/logs
        LOGFILE=${LOGDIR}/${FILE/'.sh'/''}_${CURRENT_DATE}.log
        if [[ ! -d $LOGDIR ]]; then
                mkdir -p $LOGDIR
                fnLog "Creating log dir: $LOGDIR" $C_SUCCESS
         else
                fnLog "Log file : $(cd `dirname $LOGFILE` &amp;&amp; pwd)/$FILENAME" "$C_INFO"
        fi
}
function fnGetScriptPath(){

        script_name=`basename $1`
        script_base_name=`echo $script_name | cut -d'.' -f1`

        dir_name=`dirname $1`

        if [[ $dir_name == "."  ]];then
                work_dir=`pwd`
                root_dir=`pwd | awk  'BEGIN{FS="/"; OFS = "/"} {$NF="";print}' | sed 's/.$//'`
        else
                work_dir=$dir_name
                root_dir=`echo $dir_name | awk  'BEGIN{FS="/"; OFS = "/"} {$NF="";print}' | sed 's/.$//'`
        fi

}

function fnLog() {
        echo `date +"%Y-%m-%d %k:%M:%S"` $1
        echo `date +"%Y-%m-%d %k:%M:%S"` $1 &gt;&gt; $LOGFILE
        if [[ $2 -eq 1 || $2 -eq 2 ]]; then MSG_ACCUM="$MSG_ACCUM \\n $1" ;fi
}


    function fnGetDate(){
            HDFS_SRC=$1
            HDFS_TGT=$2
            SKIP=${3:-"0"}
            for X in ${!HDFS_SRC[*]}
            do
                    #echo "comm -23 &lt;(hadoop fs -ls ${HDFS_SRC[X] } | awk -F'/' '{match(\$NF, \"[0-9]+-[0-9]+-[0-9]+\", v)}{print v[0]}' | sort) &lt;( hadoop fs -ls $HDFS_TGT | awk -F'/' '{match(\$NF, \"[0-9]+-[0-9]+-[0-9]+\", v)}{print v[0]}'"
                    HDFS=("${HDFS[@]}" "`comm -23 &lt;(hadoop fs -ls ${HDFS_SRC[X] } | awk -F'/' '{match($NF, "[0-9]+-[0-9]+-[0-9]+", v)}{print v[0]}' | sort) &lt;( hadoop fs -ls $HDFS_TGT | awk -F'/' '{match($NF, "[0-9]+-[0-9]+-[0-9]+", v)}{print v[0]}' | sort ) | grep "^[0-9]"`")
            done

            if [[ $value == "" ]];then
                    DATE=( $(
                    for x in "${HDFS[@]}"
                    do
                            echo "$x"
                    done | sort | uniq) )
                    echo ${DATE[$SKIP]}
            else
                    DATE=( $(
                    for f in ${HDFS[@]}
                    do
                            if [[ "$f" &gt; "$value" || "$f" == "$value" ]];then
                                    echo "$f"
                            fi
                    done | sort | uniq) )
                    echo "${DATE[$SKIP]}"
            fi
    }
</code></pre>