![](/img/trans.png)
[英]Running shell script on Windows via Cygwin mintty.exe doesn't execute runcoms
[英]tr command causes problems in cygwin bash.exe shell, but works in mintty.exe
我將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
看起來這兩個外殼的行為不同,但是它們似乎都是同一種外殼,因為當我echo $0
,bash.exe輸出bash
而mintty.exe輸出-bash
。
我還嘗試使用bourne shell(sh.exe)命令,但它輸出的內容與bash.exe shell相同。
有誰知道我如何使該命令與sh.exe或bash.exe Shell一起使用? 有人知道為什么兩個bash shell行為不同嗎?
您可以使用sed
和wc
做同樣的事情:
echo -n ./bootstrp3.cab | sed 's![^/]!!g' | wc -c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.