#!/bin/bash -u # $0 # -Ian! D. Allen - idallen@idallen.ca - www.idallen.com sgr0=$( tput sgr0 ) || exit $? # this outputs nothing if terminal doesn't do colour; let it pass cyan=$( tput setaf 6 ) # || exit $? while : ; do fortune=$( fortune ) len=${#fortune} # find the length without any spaces f2=$( printf "%s" "$fortune" | tr -d '[:space:]' ) len2=${#f2} # Sleep relative to the length of the text. # The -w option of fortune might also do something like this. sleep=$(( (len2+11) / 12 + 3 )) msg="$cyan length $len ($len2) -> sleep $sleep seconds$sgr0" printf "%s\n%s\n" "$fortune" "$msg" sleep $sleep done