Le Sun, Mar 08, 2026 at 06:14:32PM -0400, Greg Wooledge a écrit :
> On Sun, Mar 08, 2026 at 15:54:06 -0600, Stan Marsh wrote:
> > >When a shell script is edited while running, it appears the current 
> > >invocation takes the update right away.
> It would be the work of a few minutes to come up with an example.
> A lot longer to come up with a *good* example.

Running this:

    #!/bin/bash

    echo "This is a test script"

    script="$(sed \$s/last/second-to-last/ <$0)"
    echo "$script" >$0

    echo 'echo This line was added while running' >>$0

    echo This is the last line.

could produce something like:

    This is a test script
    This is the last line.
    ./script.sh: line 11: ast: command not found
    This line was added while running

By adding a ``sync'' command:

    #!/bin/bash
    
    echo "This is a test script"
    
    script="$(sed \$s/last/second-to-last/ <$0)"
    echo "$script" >$0
    sync
    
    echo 'echo This line was added while running' >>$0
    
    echo This is the last line.

I will read:

    This is a test script
    This is the second-to-last line.
    This line was added while running


But as Greg said, 

> It's a well-known pitfall, in any case.


-- 
 Félix Hauri  -  <[email protected]>  -  http://www.f-hauri.ch

Reply via email to