Pass variable from a child to parent in KSH

后端 未结 2 922
独厮守ぢ
独厮守ぢ 2020-12-22 08:53

I have to work with KSH (yeah that hell shell). I need to use a fork, a subroutine as following:

    #!/bin/ksh

    PIPE=PIPE_$$
    PIPE_ERR=PIPE_ERR_$$

          


        
2条回答
  •  星月不相逢
    2020-12-22 09:25

    Variables can be passed from a parent shell to child shell, not the other way around. However, you can do a workaround if you are really in need of the value set in the child shell.

    One possible workaround: In the child shell, write the env variables of your interest along with their values to a file. Once you are back in the parent shell, run this file so that the env variables needed are overwritten with what is set in the file. You can refer here for an example.

提交回复
热议问题