tr命令在cygwin bash.exe shell中导致问题,但在mintty.exe中有效

时间:2012-07-25 14:59:59

标签: bash shell cygwin sh tr

我使用Windows与cygwin。以下命令应输出字符串“./bootstrp3.cab”中出现的“/”数。当我使用mintty.exe shell并输出“1”时,它可以工作:

echo ./bootstrp3.cab | tr -cd / | wc -c

不幸的是,它使用bash.exe shell输出以下消息

Usage:
tr [-cs] string1 string2
tr -s[-c] string1
tr -d[-c] string1
tr -ds[-c] string1 string2

似乎两个shell的行为不同,但它们似乎都是同一种shell,因为当我echo $0时,bash.exe输出bash和mintty.exe输出{{1 }}

我也尝试了使用bourne shell(sh.exe)的命令,但它输出的信息与bash.exe shell相同。

有谁知道如何使用sh.exe或bash.exe shell获取命令?有人知道为什么两个bash shell表现不同吗?

1 个答案:

答案 0 :(得分:1)

您可以使用sedwc执行相同的操作:

echo -n ./bootstrp3.cab | sed 's![^/]!!g' | wc -c