Operating System - HP-UX
1834366 Members
2103 Online
110066 Solutions
New Discussion

Re: modifying a shell script while it is running

 
Marc Bohnert
Advisor

modifying a shell script while it is running

HPUX 11.0
bash shell

If I modify a shell script (add/delete lines, comment out lines) while it is executing will it abort. It seems to me that I have seen scripts abort in the past.

Any input would be appreciated.

Regards

Marc Bohnert
MedPlus
7 REPLIES 7
Stephen Keane
Honored Contributor

Re: modifying a shell script while it is running

I've certaiunly seen scripts get very upset if you edit them whilst they are running. It's not generally a good idea.
A. Clay Stephenson
Acclaimed Contributor

Re: modifying a shell script while it is running

It will not abort when asked as stated. Once read in and parsed, the file could even be removed and the script would continue to execute. However, if you edit a script that is called from another script then you could have problems because that script is read each time so if you introduced a syntax error into the called script. The next time the script is called (e.g. in a loop) a failure would occur.
If it ain't broke, I can fix that.
S.Rider
Regular Advisor

Re: modifying a shell script while it is running

Yeah, what Clay said. I've frequently modified scripts while running without problems. As long as they're not called-scripts, you should be safe. When testing scripts, I usually have 2 windows opened up. Running the script in one, editing it in the other.
Ride Boldly Ride, but watch out for El Dorado's
Bill Hassell
Honored Contributor

Re: modifying a shell script while it is running

Shell scripts are interpreted, not compiled so simple scripts are read one line at a time. For small scripts, most of it is probably in the buffer cache and in thye shell's buffers. Given a really long script (several pages long) and certain changes, the shell could get very mixed up on where it is within the script and the shell will certainly crash. It isn't easy to predict which scripts and what changes will cause a shell to crash. I hope this is an academic question and not an attempt to modify production code on the fly...


Bill Hassell, sysadmin
Biswajit Tripathy
Honored Contributor

Re: modifying a shell script while it is running

For smaller scripts, the script would be entirely in
the system memory; so any change in the script
by another process, however bad idea it may be,
will have no affect or the currently running program.

- Biswajit
:-)
Biswajit Tripathy
Honored Contributor

Re: modifying a shell script while it is running

An addition to my previous post.

A running script is always entirely loaded into the
memory irrespective of the script size, so any change
to the script while it's running will have no affect on the
running process. Ofcourse, if the script is too big and
can't be loaded into the memory entirely, the invoking
shell will get SIGSEGV (insufficient memory/swap
space) and abort.

- Biswajit
:-)
Christian Deutsch_1
Esteemed Contributor

Re: modifying a shell script while it is running

Dear Marc,

From my 22 years experience (csh, ksh, HP-UX posix shell, bash), I have found that shell scripts can do strange things even if I make a really small change and then save the script while it is running.

So if you want to be on the safe side, never save a modified script while it is running. It is safer to:
1. Copy the script and edit the copy
2. - or - save it under a different name
3. - or - wait until the script completes before saving your changes to disk

Kind regards, Christian
Yeshua loves you!