Com fold
de GNU Core Utilities :
a="Best Direction - I feel good"
fold -s -w 8 <<< "$a" | while read -r line; do
echo "PS $line" > "$fifo"
sleep 1
done
Saída para $ fifo:
PS Best PS Directio PS n - I PS feel PS good
Sem fold
com a mesma saída para $ fifo:
a="Best Direction - I feel good"
while [[ -n $a ]]; do # loop until $a is empty
if [[ ${#a} -gt 8 ]]; then
b="${a:0:8}" # get first 8 characters of $a
c="${b% *}" # crop all from right incl. first whitespace
else
c="$a"
fi
echo "PS $c" > "$fifo"
d="${a#$c}" # crop $c left from string $a
a="${d# *}" # remove a leading whitespace
sleep 1
done