Thank you rene, I understand what you're saying now. The commands are just within a function {}, no calls to external scripts or anything. I haven't posted the full script because it's just a handful of simple unrelated commands, a call to the function, the function, and exit, and it works 99% of the time.
As far as stdin goes, my observation was that the read command did not complete ( was still waiting for input ) and the command after still executed ( apparently ). I created this function to inform me of the directory's absense so I'd have time to check the directory structure for myself before continuing the script. And that part of the script worked because the read function paused the script. After checking things out, I pressed ENTER and the directory to be moved was missing-- however, I just now realized, and I feel extremely
about it, there are actually two malfunctions going on, and I'm sorry I didn't catch this earlier and confused the two problems after a long day with a deep-fried sleep-deprived brain..... Again, really sorry!
And sorry this is so complex!
So the first malfunction, as already mentioned, is the directory ( a mounted /media device ) didn't exist when it was supposed to but now I see that it's not a huge surprise given that I frequently have errors and problems with USB devices and mounting. ( Need to post about that too! My machine really does not like USB devices, will occassionally fail to mount them or straight up freeze my machine even when ejecting them safely. )
The real problem is: a file that was also supposed to be present when that read command executed was missing. That file mysteriously went missing and I can't for the life of me trace how it disappeared at that point in the script. It's only supposed to be created and destroyed at specific times and conditions in the script, and 99% of the time it works like clockwork. ( The script opens the file for decryption on startup and would bark if it was absent. In this case, it opened up and decrypted fine, but when I "closed it out" for the encryption procedure the file was missing and the device wasn't mounted so the succeeding backup operation failed. )
The file is supposed to be moved first and then recreated by openssl encryption operation. The only way the file could disappear AFAIK is if the encryption operation failed and never completed for whatever reason, but the script is programmed to retry encryption infinitely until done. Normally, killing the script prematurely or a machine freeze requiring reboot could explain this, however, I would've known if etiher of these were the case because my script didn't die, I didn't have to retry encryption, and it had opened the file to begin with as it was supposed to.
With the above realization I'd need to spend some time analyzing the process flow of the script and study contigencies of various outcomes and failures to understand how I should better keep track of the file and ensure its existence and absense in the right circumstances. So for now it's a bit of a mystery that will require work on my part to set traps for debugging and I'm sorry for getting confused and wasting your time. Now I do know for a fact, at least on my machine, bash does rarely but surely malfunction and behave extremely bizarrely from time to time and that remains a possibility. It's definitely some kind of quirk; when it happens I have to reboot and then the script works fine. ( Even commands that don't reference files or variables fail to execute properly when this occurs. ) BUT now I know what I need to do to further debug and make sure it's not me.
The problem is I'm running out of time to mess with this, but next time this problem occurs I'll know how to start debugging and will post back if I hit a brick wall.
Thanks so much, everybody! And thanks xenopeek for the stdin insights; I was actually needing that anyway!