I wrote a script and ran into an odd behavior. Some terminal windows it is run in would suddenly close before the script was completed running.
After a few hours of investigation I tracked the issue down to this line output
init: Command 'mount_all /fstab.ranchu' action=fs (/init.ranchu.rc:2) returned 0 took 1805ms.
After some more refinement I determined this is the minimum sequence needed to regenerate this problem.
.(:2)
If I type this sequence in a terminal tab in Intellij code editor that tab will, after about a second, close itself. More frustrating this problem is occurring when this script is run as part of my build/CI system.
It does not impact all terminals, for example Gnome-terminal and xterm do not have any issues with that sequence.
The digit 2 in that string can actually be any integer up to 9 digits long and it will cause the issue.
I suspect this sequence might be a terminal control sequence but I didn't find anything like that in my research.
Another odd thing is that I sometimes my script output will stall stall(buffer, I can see the script still working) for longer than expected periods.
I found this set of commands solved the buffering issue and the problem with the closing terminal but I would like to know what is going on
./example.sh |& stdbuf -eL -oL sed -s 's/:\([0-9][0-9]*)\)/:_\1/'
example.sh looks like this
#!/bin/bash
echo '.(:2)'
stdbuf configures the buffer that is used for the pipe/|&.
The sed statement takes .(:2) and turns it into .(:_2) which seems to prevent the problem.