BASH

Sean seanlkml at sympatico.ca
Sat Dec 4 16:35:48 UTC 2004


On Sat, December 4, 2004 10:50 am, Bill Gradwohl said:
> Two questions:
>
> 1) When a BASH script is executed, the file that represents the script
> must be read by the interpreter. Assuming the script is a long running
> script, is it safe to modify the script while its executing? The real
> question boils down to is the entire script read into memory or not
> before execution starts, or is it read as needed from disk. I ask
> because I'd like to test a script, and while its running and I see
> errors, I'd like to modify the script without disturbing the executing
> version.
>

It is not safe to edit a running script...

Try this; create a file named "script" containing:

#!/bin/sh
echo "press enter"
read x

run script... and from a second command prompt do:

echo echo modified while running  >> script

Go back to the window running script and press enter...
and you'll see your modification is exectuted.

If the particular editor you use completely replaces updated files when
you save rather than updating them, you will get away editing a running
script.   Still hard to recommend it as a practice.

> 2) There seems to be no way to "goto" in BASH. If one has a lengthy
> script that fails half way down, the only thing to do appears to be to
> wrap the top half in an if that won't execute so as to skip that top
> half and get to where the script should again restart. Is there a better
> way to do this?

Refactor your code using functions like so:

#!/bin/sh
main() {
   echo "do stuff here"
}

while true
do
     main
done

Cheers,
Sean





More information about the fedora-list mailing list