I'm creating script that will display 2 times the song name in FM radio station name. Radio station name is limited to 8 characters. Lets say I have this line: Best Direction - I feel goodThe code will look like this: (the PS is start of line software know it's command to change name)echo PS Best > $fifo;sleep 1;echo PS Directio > $fifo;sleep 1;echo PS n - I > $fifo;sleep 1;echo PS feel > $fifo;sleep 1;echo PS good > $fifo;sleep 1;//repeat this one more timeHow to do that in bash script? I have no idea.
Split line to words of maximum size of 8 characters
bash;shell script;scripting
With fold from GNU Core Utilities:a=Best Direction - I feel goodfold -s -w 8 <<< $a | while read -r line; do   echo PS $line > $fifo sleep 1doneOutput to $fifo:PS BestPS DirectioPS n - IPS feelPS goodWithout fold with same output to $fifo:a=Best Direction - I feel goodwhile [[ -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 1done