I have a master script which has few function definition. Using a child script im trying to call the master script along with passing the arguments to the function. Problem here is my master script is getting executed twice. 1. Everytime when i call my child script, Firstly all the function in master script is getting executed without any argument (i.e. Empty arguments) 2. Then second time Argument value is getting passed and executing the function successfully as expected.
Kindly let me how to avoid the execution of step-1 specified above.
I have tried with source (or) . followed by specifying the master script inside the child script and then followed by specifying the function name along with arguments. But it is not working.
Child Script :
source <directory_path>/master.sh
add '123' 'get' 'R'
Master Script :
#! /bin/bash
add()
{
exec &> $1_$(date "+%Y%m%d%H%M").log
Change=$1
Command=$2
if [[ $Command == "get" ]];
then Command_1="getfacl"
elif [[ $Command == "set" ]];
then Command_1="setfacl"
elif [[ $Command == "ch" ]];
then Command_1="chown"
else Command_1="ls"
fi
Tag=$3
if [[ -z "$Tag" ]];
then Tag=""
else Tag="-$Tag"
fi
}
add;
Child Script :
source <directory_path>/master.sh
add '123' 'get' 'R'
Only one file should get generated as per the script. But actual result generates 2 files.
Expected Result
123_201909201012.log
Actual Result
_201909201012.log
123_201909201012.log