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:]' )
$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:]'
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
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;
bashversion is 4.3.42(4);
- Right now I have absolutely nothing in
/etc/bash.bashrc. Not sure about before Rtools;
- I can't see anything wrong in