Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Of course you can set a variable in this way. You do not need a temp file. You set in the variable in the subshell and print its value to parent shell where you absorb that value. You get all of the state you need to compute its value in the subshell so that's where you do it. Commented Apr 15, 2014 at 16:07
  • 1
    @mikeserv That's not the same thing, which is why the OP has said such a solution will not work (although this should have been made more clear in the question). What you are referring to is passing a value to another process via IPC so that it can assign that value to whatever. What the OP wanted/needed to do was affect the value of a global variable shared by a number of processes, and you cannot do that via the environment; it is not very useful for IPC. Commented Apr 15, 2014 at 16:17
  • Man, either I've completely misunderstood what is needed here, or everyone else has. It seems really simple to me. You see my edit? What's wrong with it? Commented Apr 15, 2014 at 16:27
  • @mikeserv I don't think you've misunderstood and to be fair, what you have is a form of IPC and could work. It's not clear to me why Konrad doesn't like it, but if it isn't flexible enough, then the file stash is pretty straightforward (and so are ways to avoid collisions, e.g. mktemp). Commented Apr 15, 2014 at 16:38
  • 2
    @mikeserv The intended function is called when the value of PS2 is expanded by the shell. You don't have an opportunity to update the value of a variable in the parent shell at that time. Commented Apr 15, 2014 at 17:16