Skip to main content

Timeline for Stateful bash function

Current License: CC BY-SA 3.0

6 events
when toggle format what by license comment
Apr 15, 2014 at 17:16 comment added chepner @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.
Apr 15, 2014 at 16:38 comment added goldilocks @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).
Apr 15, 2014 at 16:27 comment added mikeserv 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?
Apr 15, 2014 at 16:17 comment added goldilocks @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.
Apr 15, 2014 at 16:07 comment added mikeserv 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.
Apr 15, 2014 at 15:49 history answered goldilocks CC BY-SA 3.0