export doesn't work in a background process

前端 未结 1 1998
悲哀的现实
悲哀的现实 2021-01-23 18:29

pipe.sh

 export START=100
 . ./other.sh &
 wait

other.sh

sleep 5
export END=200
相关标签:
1条回答
  • 2021-01-23 19:17

    A child process cannot change parents environment, you need to declare the variable from the parent somehow. For example using a file:

    pipe.sh:

    export START=100
    . ./other.sh > tmp &
    wait
    source tmp
    rm tmp 
    echo $END
    

    other.sh:

    sleep 5
    echo "export END=200"
    

    Also see this answer.

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