Usually I can solve problems on my own (and Google). But recently I am baffled by this strange hiccup.

Background: I use a chain of scripts for file-processing (in Windows, under Cygwin. Scripts also run on OS X with gnu baseutil). One day after installing Rtools, my scripts stopped working. After much hassle, I've managed to identify a problem.

Problem: I have the following line:

key=$( echo "$foo" | tr -d - | tr '[:upper:]' '[:lower:]' )

where $foo is just another text variable. I remove dashes in $foo and convert it to lower-case. The script worked thousands of times.

But now it doesn't. If I run

echo "Blah-Bleh" | tr -d - | tr '[:upper:]' '[:lower:]'

I get blahbleh which is expected. But if I do

a=$(echo "Blah-Bleh" | tr -d - | tr '[:upper:]' '[:lower:]')
echo $a

I get nothing. $a is empty and [[ -z $a ]] returns true. However, if I revert to old school backticks, the command works again:

a=`echo "Blah-Bleh" | tr -d - | tr '[:upper:]' '[:lower:]'`
echo $a

gives blahbleh.

Now I can replace all command substitutions with the older style, but that's more of a workaround than a solution. So my fellow StackExchangers, what am I missing and how do I fix it? It's really irritating.

ps. My own diagnostic so far:

  • Uninstalling Rtools did not help;
  • Restarting the machine did not help;
  • Reinstalling every Cygwin package did not help;
  • bash version is 4.3.42(4);
  • Right now I have absolutely nothing in ~/.bashrc, ~/.bash_profile, ~/.profile, /etc/profile and /etc/bash.bashrc. Not sure about before Rtools;
  • I can't see anything wrong in $PATH.
  • rtools as cygwin package or as windows package ? If windows, do the path includes both ? Have you looked at cygcheck -s -v -r > cygcheck.out output for hints ? – matzeri May 27 '16 at 20:44
  • @matzeri Rtools as Windows package. I knew it included cygwin component but I just couldn't find out where. I think you are right, cygcheck reports *** fatal error - cygheap base mismatch detected - 0x18033E400/0x2B0E400. It seems my cygwin DLL is messed up. However, Rtools is not in the path. I remember specifically selecting not to modify path when installing. – Yifeng Mu May 27 '16 at 21:05
  • Remove Rtools from PATH when using cygwin and viceversa. Rtools contains a mini cygwin system in `rtools/bin' – matzeri May 27 '16 at 21:20
  • That “cygheap base mismatch” message indicates the problem. It's a problem with DLL, and PATH settings have no impact on that. When multiple programs use the same DLL on Windows, it's loaded at the same address in all of them, and this can sometimes cause conflicts when different libraries end up overlapping. I thought rebooting would solve the problem. Since it doesn't, I suggest to ask Windows experts: flag your question and request a migration to Super User. – Gilles May 28 '16 at 18:50
  • if Rtools is in the PATH before Cygwin, the cygwin1.dll of Rtools will be used instead of the cygwin installation. As some of cygwin programs are expecting their version of cygwin1.dll that is later than rtool one. Cygwin doen's work because of that. The only solution is to NOT have both in the PATH. – matzeri May 29 '16 at 10:19

OK, after a lot of fiddling and hair pulling, I've managed to restore Cygwin to working order. This is what I did:

  1. Removed Rtools
  2. Cleared and Windows %PATH% of anything Cygwin/Rtools related entry;
  3. Reinstalled all Cygwin packages (from cache);
  4. Rebased Cygwin;
  5. And restarted the computer more often than needed.

Back to work...

PS. Despite Cygwin being working again, I discovered that the original line where I assign values to a bash array isn't producing the right result any more. Had to change this

read -r -a array <<<$(printf $string)

to this

array=($(printf $string))

to make it work. Must have been a bash update, must be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.