bash学习过程中的疑问2:使用参数扩展来获取字符串的第i个字符为什么不对?

https://www.hackerrank.com/challenges/text-processing-cut-1/problem

img


我的解答:

while read line
do
    echo ${line:2:1}
done

错误测试样例:
Input

C.B - Cantonment Board/Cantonment
C.M.C – City Municipal Council
C.T – Census Town
E.O – Estate Office
G.P - Gram Panchayat
I.N.A – Industrial Notified Area
I.T.S - Industrial Township
M – Municipality
M.B – Municipal Board
M.C – Municipal Committee

my output

B
M
T
O
P
N
T
–
B

expect output

B
M
T
O
P
N
T

B
C

不仅少算了一行,而且第8个的输出也不对。

img

看下提示,是使用cut完成


cut -d ' ' -f 1|cut -c 3

img

我觉得应该是这道题有问题。
题目中说明了A text file containing lines of ASCII characters.
但是在测试用例出现的M – Municipality中的并不在ASCII中。
(少算了一行,应该是网站限制了用户自己测试样例的长度)