出于某种原因,我不能用它bash
来构建我的脚本,唯一的方法是使用ash
,我有这个 sms 自动回复脚本,每个回复必须最多 160 个字符长,它看起来像这样:
#!/bin/sh
reply="this is a reply message that contains so many words so I have to split it to some parts"
array="${reply:0:5} ${reply:5:5} ${reply:10:5} ${reply:15:5} ${reply:20:5}"
for i in $array
do
echo "send sms with the message: $i"
done
但它最终是这样的:
send sms with the message: this
send sms with the message: is
send sms with the message: a
send sms with the message: reply
send sms with the message: mess
send sms with the message: age
send sms with the message: t
我想要的是这样的:
send sms with the message: this
send sms with the message: is a
send sms with the message: reply
send sms with the message: messa
send sms with the message: ge th
send sms with the message: at co
send sms with the message: ntain
所以它按字符数分割而不是按单词分割,我该怎么做?