I'm bored and I decided to write a script for a text adventure using bash. Basically, he should animate a typewriter in some cases for a dramatic narrative. I can do this manually in a file as follows:
sleep 0.1 echo -n "h" sleep 0.1 echo -n "e" sleep 0.1 echo -n "l" sleep 0.1 echo -n "l" sleep 0.1 echo -n "o"
As you can imagine, this is terribly tiring. Instead, I want to draw characters from a line (or file) one character at a time and apply a sleep command for each character.
So far, I have the following which is read from a file. IFS = allows you to save spaces, but not any other type of spaces (e.g. newline).
IFS= while read -n1 achar do echo $achar done < aFile
Is there a way I can use this to get all the spaces? As a bonus question, can you tell me how to apply this to a custom script, so I don't need to read from a separate file? So, for example, let's say I have a line called "hello" and I can just pass it to my animation function as a typewriter whenever I run my file in a bash terminal.
Any help would be greatly appreciated. Thanks!
source share