The desired behavior may not be possible, depending on the complexity of the shell scripts that are involved.
If the full shell script is contained in a file with one source code, and this file is fully parsed before execution, then the shell script is usually safe from changes to the copy on disk at runtime. Wrapping all executable statements into a function (or a series of functions), as a rule, will achieve its goal.
#!/bin/sh doit() {
The difficulty arises when the shell script “includes” other shell scripts (for example, “.” Or “source”). If they include wrapped functions, they are not parsed until this statement is reached in the thread of execution. This makes the shell script vulnerable to changes to this external code.
In addition, if the script shell runs any external program (for example, a script shell, a compiled program, etc.), this result is not fixed until this execution point is reached (if at all).
#!/bin/sh doit() { if [[some_condition]] ; then resultone=$(external_program) fi }
Stan Graves Feb 18 2018-10-18T00 : 00Z
source share