Possible to change directory and have change persist when script finishes?

后端 未结 1 1296
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 21:20

In trying to answer a question for another user, I came across something that piqued my curiosity:

import os
os.chdir(\'..\')

Will change t

1条回答
  •  北海茫月
    2021-01-18 22:19

    There is no way to do that because calling Python or bash will run everything within their own context (that ends when the script ends).

    You could achieve those results by using source, since that will actually execute your (shell) script in the current shell. i.e., call your example script with source foomaker.bash instead of bash foomaker.bash

    0 讨论(0)
提交回复
热议问题