This is the solution that will work for your case.
Break your script into functions, and each time a function is called you
source it from a separate file. Then you could edit the files at any time and your running script will pick up the changes next time it gets sourced.
I have created 2 scripts say
called.sh as below.
#The contents of callee.sh script is as below.
#The contents of called.sh script is as below.
Now, I execute
callee.sh which in turn calls my
called.sh script. Basically,
called.sh is the script which we will be changing dynamically.
callee.sh is getting executed, I open another shell and change the contents as,
echo "I added more contents here"
Now, in the first shell from which I called the script
callee.sh after the
sleep is over, the output I get is,
As you could see, I did not get the
I added more contents here in my output which is what the desired end result is.