I am writing a script, which I would like to spice up a bit.

What I need, is a loop, which takes one letter at a time, including space, and then write it on the screen, like an old typewriter would do.

I would write some kind of pause/sleep between the typing, so it would look retro like.

  • Isn't using the commandline retro enough? – Anthon Nov 9 '14 at 12:10

If you don't mind not using pure shell script (i.e., you can mix awk or perl), here it is an example using awk:

echo "This is... test this" |awk '{
  for (i=1; i <= length($0); i++) {
    printf substr($0,i,1);
    system("sleep 0.1");
  print "";
  • Perfect :) Thanks... working as expected! – Jesper Lykke Nov 9 '14 at 10:36
  • But i would like to use a string e.g text="testsssttt !!" – Jesper Lykke Nov 9 '14 at 10:37
  • This works okay ! – Jesper Lykke Nov 9 '14 at 10:39
  • #!/bin/sh text1="tessssstttttt................... !!!!" echo $text1 |awk '{ for (i=1; i<= length($0); i++) { printf substr($0,i,1); system("sleep 0.1") } print ""; }' – Jesper Lykke Nov 9 '14 at 10:40
  • @JesperLykke If this answer solves your issue please take a minute and click the check mark under the vote count to the left, this will signify to everyone that your issue's been resolved and is the way that thanks are expressed in the site. – terdon Nov 9 '14 at 12:54

There is some GNU utilites (for example pv can do the task echo "$line1" | pv -qL 10) but if you'd like can do it in shell

while [[ -n "$1" ]]
 sleep ${2:-"0.2"}
 printf "%c" "$1"
 set -- "$temp" "$2"

USAGE: script.name 'text in single quotes' [interval time in seconds][1] If you'd like to use variable do the same:

line1='Test this… test this!'
script.name "$line1" 0.3

[1]: interval time in seconds is optional and decimal fraction is allowed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.