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
.
Best Answer
OK, after a lot of fiddling and hair pulling, I've managed to restore Cygwin to working order. This is what I did:
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
to this
to make it work. Must have been a bash update, must be.