Ryan Harkin | aef265c | 2012-08-13 17:47:46 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Echos a string with a delay between each character |
| 3 | # When a # character is encountered, it's replaced with a 1 second pause |
| 4 | # and the # is NOT echoed out |
| 5 | # |
| 6 | # When there are no params: |
| 7 | # - take stdin as the string |
| 8 | # Where there is 1 param: |
| 9 | # - take the contents of the file in param 1 as the string |
| 10 | |
| 11 | # Decide where to get the string |
| 12 | if [ $# -eq 0 ] |
| 13 | then |
| 14 | str=`cat` |
| 15 | else |
| 16 | str=`cat $1` |
| 17 | fi |
| 18 | |
| 19 | # Break the string into characters and echo them 1 at a time |
| 20 | while [ -n "$str" ] |
| 21 | do |
| 22 | # if [[ "${str:0:1}" = *$'\x0a'* ]] |
| 23 | # then |
| 24 | # printf "%c" "$str" |
| 25 | # sleep 2 |
| 26 | # elif [[ "${str:0:1}" = *$'#'* ]] |
| 27 | if [[ "${str:0:1}" = *$'#'* ]] |
| 28 | then |
| 29 | sleep 1 |
| 30 | else |
| 31 | printf "%c" "$str" |
| 32 | sleep 0.05 |
| 33 | fi |
| 34 | str=${str#?} |
| 35 | done |
| 36 | printf "\n" |
| 37 | |