Shell script works fine as a standalone script but not as part of a bigger script

Hello all,

I am facing a weird issue while executing a code below -

#!/bin/bash
cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset
sh UKBA_publish.sh UKBA 28082015 3
if [ $? -eq 0 ]
then
echo "Param file conversion for all the areas are completed, please check in your home directory"
else
echo "The final PSET failed"
fi

When I execute it as a standalone code it works fine but when I execute it as a part of below mentioned script, it fails -

#!/bin/bash
param1=$1
param2=$2
param3=$3
email=$4
baot_id=$5
header_date_14=$(m_dump /wload/baot/app/data_abinitio/serial/uk_cust/ukrb_ukba_acnt_bde27_src.dml $param1 | head -35)
hdr_dt_14=$(echo "$header_date_14" | awk '$1=="bdfo_run_date" {print $2}')
julian_date_14=$(m_eval '(date("YYYYMMDD"))( unsigned integer(2)) '$hdr_dt_14'') 2>&1
header_date_15=$(m_dump /wload/baot/app/data_abinitio/serial/uk_cust/ukrb_ukba_acnt_bde27_src.dml $param2 | head -35)
hdr_dt_15=$(echo "$header_date_15" | awk '$1=="bdfo_run_date" {print $2}')
julian_date_15=$(m_eval '(date("YYYYMMDD"))( unsigned integer(2)) '$hdr_dt_15'')
header_date_16=$(m_dump /wload/baot/app/data_abinitio/serial/uk_cust/ukrb_ukba_acnt_bde27_src.dml $param3 | head -35)
hdr_dt_16=$(echo "$header_date_16" | awk '$1=="bdfo_run_date" {print $2}')
julian_date_16=$(m_eval '(date("YYYYMMDD"))( unsigned integer(2)) '$hdr_dt_16'')
echo "This is your Header date $julian_date_16"
if [ "$julian_date_14" = "$julian_date_15" -a "$julian_date_15" = "$julian_date_16" ]
then
echo All the dates from three input files are same
else
echo Check the file dates please
fi
cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset
Param_date=`echo $DATE_FINAL | cut -c7-8`
Param_month=`echo $DATE_FINAL | cut -c5-6`
Param_year=`echo $DATE_FINAL | cut -c1-4`
Param_date_1="$Param_date$Param_month$Param_year"
echo "Date to execute final PSET is $Param_date_1"
sh UKBA_publish.sh UKBA Date_FINAL 3
if [ $? -eq 0 ]
then
echo "Param file conversion for all the areas are completed, please check in your home directory"
else
echo "The final PSET failed"
fi
cd /wload/baot/app/data_abinitio/abinitio_UKBA_BDE_PUB_DISK/mfs/mfs_6way/EXTRACTS/UKBA/ext_ukba_bde_pub/main/daily
m_cp *$DATE_FINAL.SNAP.gz /wload/baot/home/$baot_id
cd
m_gunzip *20150828.SNAP.gz

Param1,Param2, Param3 and Param 4, Param 5 are required as a command line arguments.
Error is below -

Trouble creating layout "layout-Process_DETAIL.Rollup_to_account_level_within_files":

Failed computing working directory: No such file or directory
  Path = "mfile:/wload/baot/app/data_abinitio/abinitio_PBE_DISK/mfs/mfs_6way/EXTRACTS/UKBA/ext_ukba_bde/main/."

air sandbox run ukba_bde_validation_publish_ebcdic_TEST.pset failed
The final PSET failed

My point is why this code works as a standalone one and not with a script in the same environment. LinuxLinuxLinux
I am using AIX.
Any pointers will be greatly appreciated.

---------- Post updated at 08:38 AM ---------- Previous update was at 05:22 AM ----------

@VBE

sh UKBA_publish.sh UKBA Date_FINAL 3

should it not be:

 sh UKBA_publish.sh UKBA $Date_FINAL 3  ?

No, since script accepts 3 parameters, UKBA is area name and has to be hardcoded, date is the date, 3 is number of files.

You do realize that the two are not the same in that the bigger script attempts to extract parameters.
You seem to be using two different methods to build your variables:

header_date_14=$( ...

and

Param_date=` ...

You may want to re-write the 2nd set to be in the format as the 1st set. I remember there being some caveats/warnings about the use of each.

I know very well you give 3 parameters... When I added that remark its because in your attempt:

sh UKBA_publish.sh UKBA 28082015 3

You entered a value for your second whereas

sh UKBA_publish.sh UKBA Date_FINAL 3

you give a string not a VARIABLE...