随着sed上dash的壳LANG=en_US.UTF-8,我得到了以下工作的权利:$ echo "你好嗎 新年好。全型句號" | sed -e 's/\(.\)/\1\n/g'你好嗎新年好。全型句號和$ echo "Hello world" | sed -e 's/\(.\)/\1\n/g'Helloworld因此,输出可以与 while read ... ; do ... ; done针对示例文本进行了编辑,将其翻译成英文:"你好嗎 新年好。全型句號" is zh_TW.UTF-8 encoding for:"你好嗎" = How are you[ doing]" " = a normal space character"新年好" = Happy new year"。全型空格" = a double-byte-sized full-stop followed by text description
${#var} 返回的长度 var${var:pos:N}从pos开始返回N个字符例子:$ words="abc"$ echo ${words:0:1}a$ echo ${words:1:1}b$ echo ${words:2:1}c因此很容易迭代。其他方式:$ grep -o . <<< "abc"abc要么$ grep -o . <<< "abc" | while read letter; do echo "my letter is $letter" ; done my letter is amy letter is bmy letter is c