Could replacing a bash script with a new version cause a running instance of the script to fail

前端 未结 4 1024
轻奢々
轻奢々 2021-01-03 23:58

I am running bash scripts from java programs on a server. I just uploaded a new version of the script intending the next run of the script to use the version. I did not mean

4条回答
  •  感情败类
    2021-01-04 00:37

    Upon invocation, bash will fork off a new process and load the script into memory. Unless the script references itself, it should still work. Here is an example of a script both deleting itself from disk and still working until it tries to access itself via $0

    Input

    #!/bin/bash
    
    echo "I can't take it anymore"
    echo "Goodbye World!"
    
    rm -f "$0"
    
    echo "Wait, I change my mind!"
    
    sed 's/Goodbye/Hello/' "$0"
    

    Output

    $ ./suicide.sh
    I can't take it anymore
    Goodbye World!
    Wait, I change my mind!
    sed: can't read ./suicide.sh: No such file or directory
    

提交回复
热议问题