Edit shell script while it's running

前端 未结 11 1923
余生分开走
余生分开走 2020-11-27 03:18

Can you edit a shell script while it\'s running and have the changes affect the running script?

I\'m curious about the specific case of a csh script I have that batc

11条回答
  •  天命终不由人
    2020-11-27 03:40

    An interesting side note - if you are running a Python script it does not change. (This is probably blatantly obvious to anyone who understands how shell runs Python scripts, but thought it might be a useful reminder for someone looking for this functionality.)

    I created:

    #!/usr/bin/env python3
    import time
    print('Starts')
    time.sleep(10)
    print('Finishes unchanged')
    

    Then in another shell, while this is sleeping, edit the last line. When this completes it displays the unaltered line, presumably because it is running a .pyc? Same happens on Ubuntu and macOS.

提交回复
热议问题