Overwrite a running shell script

Hello all,

This might be a dumb question...but i am running into this situation.

I have a shell script that is currently in running state. It has big sql's in it and will run for few days. What happens if I change the shell now?

Eg: a.shl is running and i want to mv b.shl a.shl

I have tested this and I am getting the results of a.shl (fyi-->b.shl has different content compared to a.shl)

Once it got started execution, moving or editing wont do anything.

The script you had originally will only get executed, if you have to change, you have to kill that process, and start the new again.

A simple way to find out is try out on some other shell script. Write a shell script that does nothing but sleep for a few seconds. (sleep 10). While it is being excuted in a terminal, from another terminal, delete/rename it.

Thanks for your inputs. As long as it takes the original script I am fine.

Don't think you can count on that. Whether or not the shell keeps a local copy in memory is shell-specific, I've caused long-running BASH scripts to bomb out with syntax errors by modifying them while in execution. Strangely, deleting it may be safer than that -- if the shell already has a handle to the file, that handle will remain valid! The file will only truly be freed from disk once it's closed for the last time.

If you need to derive one script from another, make a copy, don't rip the floor out from under something else.

I agree with Corona688. Overwriting a script while it is running can cause the script to fail and/or to execute commands out of context.