tr command causes problems in cygwin bash.exe shell, but works in mintty.exe
Question
I use Windows with cygwin. The following command should output the number of occurrences of '/' in the string "./bootstrp3.cab". It works when I use the mintty.exe shell and outputs "1":
echo ./bootstrp3.cab | tr -cd / | wc -c
Unfortunately it outputs the following message with the bash.exe shell
Usage:
tr [-cs] string1 string2
tr -s[-c] string1
tr -d[-c] string1
tr -ds[-c] string1 string2
It seems that the two shells behave differently, but they both seem to be the same kind of shell, because when I echo $0
, bash.exe outputs bash
and mintty.exe outputs -bash
.
I also tried the command with the bourne shell (sh.exe), but it outputs the same message as with the bash.exe shell.
Does anyone know how I can get the command working with the sh.exe or bash.exe shell? And does someone know why the two bash shells behave differently?
Solution
You can do the same thing using sed
and wc
:
echo -n ./bootstrp3.cab | sed 's![^/]!!g' | wc -c