Can an interactive shell become non-interactive or vice versa?
Note: I've done a lot of research on the basic question, "What is the difference between interactive and non-interactive?", and the results of my research led me to ask this question.
This question has a long preamble in part becaus...
Interesting question. The usual way for a utility to check whether it's run interactively or not (i.e. as part of a pipeline) is to check whether stdin and stdout are connected to a TTY.
For example, a non-interactive sub-shell: echo hello | ( tty; cat ).
@Kusalananda Yep, that would be an example of the fact that "interactive" is really just a common label rather than a totally precise item.
So utilities which check TTY have a good proxy. But if the shell is run with bash -i, then it's not saying whether the shell is "interactive."
Point being (as noted in my question), that I don't think "interactive" is really a finite definite thing. But there are certainly behaviors of the shell which indicate that the TTY connections and $- check are not all the ways that "interactive" is noted or stored by the shell.
Heh, is that you @Wildcard upvoting my questions about interactive shells? Looks like you're doing your homework :)
And very interesting question, by the way. Although a bit on the long side. On the other hand, I don't see where else you could put your research so. . .
@terdon Yeah, I know. I occasionally (while I was writing and scrapping and rewriting the question over like a 4 hour period) considered just reducing to one sentence: "Does set +i actually do anything?" but it made me feel like crying with exasperation, and it wouldn't have really accomplished anything—
(since evidently the answer is "no," but I don't understand how that's possible). So I decided to just emphasize all the actual questions in there and leave the research in place as well.
@Kusalananda THAT question would be irrelevant and unanswerable. But there are a few specific, concrete behaviors of what's called an "interactive shell" that cannot be understood (or changed!) by reference to the documentation. I want to know how those "options" (behaviors) are registered or kept track of, since they seem to be magically remembered regardless of tearing down job control, closing streams, etc.
(I didn't try all teardown possible, but I did enough to make an interesting question.)
What if "being an interactive shell" is just a shell initialization thing? The shell enables job control and all the other things. After that, does it have to know it's "interactive"?
@Kusalananda Originally I just wanted to understand what "interactive" meant, fundamentally. I answered that satisfactorily for myself. Individual traits of a default interactive shell can be checked for individually (shopt -o histexpand, etc.), and there is no single global trait that qualifies a shell as "interactive."
Just as with my "being alive" analogy. I ask "are you alive?". You say "yes", but how do you know? You don't wear a "being alive" thing that someone can take away, but you can check distinct things like thinking, breathing, able to move etc.
The only remaining thing left to clear up, then, are the few behaviors for which I don't even see or understand how the shell registers or remembers (or changes) those behaviors. They are part of the nebulous "interactiveness" of the shell, and aren't predictable otherwise.
@Kusalananda Hence my preamble about action definitions. A label is a label. The things you label with it are so labeled. That doesn't make it possible to do anything with that label. It's a "descriptive definition" only, not dynamic in the slightest. If you define the label "alive" as applying to a person who has stopped breathing, but only if they are still warm and are not underwater—then that person is "alive" by your definition. Great. Useless.
By contrast, you could take a dynamic concept like "possible to resuscitate if given immediate attention, but otherwise certain to remain dead," and now you have an action definition. You can do something with this definition. You can use it to bring about a changed condition (changed state of being) on the part of this item of interest. Or bring about action or inaction. Use it to accomplish something else. It has a purpose.
I'm sitting with a piece of scientific software that has a load of function pointers and void * data structures everywhere. It's hairy, and it leaks. It's very tricky to even see what structures leak sometimes, and even more tricky to figure out how to properly deallocate them when the allocations happens in all sorts of places at different times.
I was going to say "that's academic software development for you" but then I'd be shooting myself in the foot, being an academic software developer...
Valgrind is a big help, but I wouldn't want to have to run a browser through Valgrind and then have to track don all the leaks.
@FaheemMitha It's C. The software is 10+ years old. It has a big user-base, and it's in "maintenance mode", which is why I have been entrusted with maintaining it (it's one of the things we do).
@Kusalananda I have no idea where exactly Chrome leaks, but Firefox is maybe in JS or DOM. Leaving some pages open take out the browser pretty quickly, others not at all.
I've often wondered if Firefox wouldn't work better if you added a half TB of swap and disabled its garbage collector
Because it's GC has the problem that it hangs the browser for hundreds of ms, and fails to collect any garbage. Then it repeats a few seconds later. Until you eventually give in and restart the browser.
chat.SE used to be one of those sites that'd kill it in a day or two. Not sure if it still does, but that's why I use Chromium—mainly for chat.SE.