1

I encountered some bizarre Bash behavior today, and maybe it's a bug that's since been fixed, but I'm going to ask about it anyway.

I have an x64 Cygwin install on my work computer with Bash 4.3.46 in it. By accident today, instead of typing !533 to run an old command in my history, I typed ~533. That should have just displayed nothing, since I had an empty directory stack.

But instead, ~n seems to freeze Bash, for any number n. Open a brand-new MinTTY with Bash in it, type ~1 and hit Enter, and Bash just disappears into la-la land. Ctrl+C, Ctrl+J, Ctrl+Z, Ctrl+anything can't get you back to a prompt. Characters you type are echoed to the console, which is mildly interesting, since something must still be echoing them. But you can't recover the shell, and you can't even close MinTTY normally — you have to force-kill the Bash process ID.

It's worth noting that dirs +1, which is supposed to be the equivalent of ~1 (per the Bash manual), works just fine.

I can reliably reproduce this on my work computer. Interestingly, Cygwin Bash 4.4.12 on my home computer works right, so this may be a bug in the 4.3.x versions that they fixed in 4.4.x. If it is a bug, I'll definitely upgrade.

So is this broken tilde behavior a bug? A misconfiguration? Has anyone encountered this behavior before?

Sean Werkema
  • 5,810
  • 2
  • 38
  • 42
  • Any chance it's trying to resolve the home directory of a user with that number as their username and having to check a network login server or something? – Eric Renouf Jul 06 '17 at 17:04
  • I don't think so. My work computer is connected to Active Directory, but Cygwin shouldn't know or care about that; it should only be looking at what's in `/etc/profile` or in `/home`, and I'm the only person who uses this computer, so those are fairly bare. On top of that, I'm typing `~1`, and not `~1/` or `~1`, so it shouldn't be trying to resolve anything anyway: The Bash manual says that's equivalent to `dirs +n`, and isn't some kind of home-directory resolution operation. – Sean Werkema Jul 06 '17 at 17:08
  • `~` will still resolve to that user's home directory, even without a tab or trailing slash. I wouldn't be surprised if cygwin tries to resolve to windows users too, but I don't know that for sure. The first time you open a cygwin shell as a windows user it sets everything up without you having to take special steps to create a cygwin user – Eric Renouf Jul 06 '17 at 17:25
  • Works as expected for me : $ ~533 -bash: ~533: command not found – matzeri Jul 06 '17 at 17:52
  • A few more useful data points: I left a window open with `~1` in it, and it's still frozen after an hour. Also, there's 0% CPU usage for the Bash process, so it's either waiting on I/O or deadlocked. – Sean Werkema Jul 06 '17 at 18:42
  • Happened to me today when I used ~user and tried to use tab completion to get the rest of the username. Somehow that poisoned the bash session. I had to start a new bash and avoid tab completion when using tilde. – JohnMudd Jan 25 '21 at 21:36
  • For what it's worth, I've long since switched from Cygwin to WSL (and to WSL2 on some of my computers). Cygwin was the best solution you could get for "Unix on Windows" — until Microsoft offered their own. I don't know if this issue still persists, but after using WSL, I don't feel a need to go back to Cygwin. – Sean Werkema Jan 26 '21 at 20:25

0 Answers0