This might not be the general practice being followed by script writer .
Most of the time it is recommended to write a function inside a script and call it whenever necessary.
Create script.sh and test.sh in /usr/local/sbin
Parent Script.
# cat script.sh
# script.sh file
[[ -f /usr/local/sbin/test.sh ]] && . /usr/local/sbin/test.sh
Var=123
echo "Calling Function"
echo "Value of Var is $Var"
my_test
echo "Returning the control"
Child Script.
# cat test.sh
my_test()
{
echo "Just testing here:)"
echo "Value of Var is $Var"
}
Now execute the parent script.
./script.sh
# ./script.sh
Calling Function
Value of Var is 123
Just testing here:)
Value of Var is 123
Returning the control
No comments:
Post a Comment