How to print text in the terminal as if it's being typed?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
26
down vote

favorite
7












I have a simple echo print out that I've added to my .bashrc:



echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
sleep 2s
echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
echo "$(tput setaf 2)Wake up neo....."
sleep 2s
echo "$(tput setaf 2)The Matrix has you......"
sleep 2s
reset
echo "$(tput setaf 2)Follow the white rabbit......"
sleep 2s
reset
cmatrix


This prints a message to terminal, but I want it look as though it's being typed, with a consistent delay between characters.







share|improve this question


















  • 1




    To be realistic I think you should have random typo thrown in with one or more back spaces to correct. For example whilst typing this comment I had to back space over "through" to correct it to "thrown". It makes it a more difficult question to answer but it makes it more realistic. If characters repeat at a steady pace of 30 CPS or 60 CPS it look less human. Certain keys are typed faster together, whilst other key combinations appear slower. Some sort of pattern matching of key combinations to speed is needed.
    – WinEunuuchs2Unix
    May 1 at 3:55







  • 2




    @WinEunuuchs2Unix I don't think this is still SimplySimplified. ;)
    – dessert
    May 1 at 10:28






  • 1




    See my answer here
    – Dennis Williamson
    May 1 at 23:34














up vote
26
down vote

favorite
7












I have a simple echo print out that I've added to my .bashrc:



echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
sleep 2s
echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
echo "$(tput setaf 2)Wake up neo....."
sleep 2s
echo "$(tput setaf 2)The Matrix has you......"
sleep 2s
reset
echo "$(tput setaf 2)Follow the white rabbit......"
sleep 2s
reset
cmatrix


This prints a message to terminal, but I want it look as though it's being typed, with a consistent delay between characters.







share|improve this question


















  • 1




    To be realistic I think you should have random typo thrown in with one or more back spaces to correct. For example whilst typing this comment I had to back space over "through" to correct it to "thrown". It makes it a more difficult question to answer but it makes it more realistic. If characters repeat at a steady pace of 30 CPS or 60 CPS it look less human. Certain keys are typed faster together, whilst other key combinations appear slower. Some sort of pattern matching of key combinations to speed is needed.
    – WinEunuuchs2Unix
    May 1 at 3:55







  • 2




    @WinEunuuchs2Unix I don't think this is still SimplySimplified. ;)
    – dessert
    May 1 at 10:28






  • 1




    See my answer here
    – Dennis Williamson
    May 1 at 23:34












up vote
26
down vote

favorite
7









up vote
26
down vote

favorite
7






7





I have a simple echo print out that I've added to my .bashrc:



echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
sleep 2s
echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
echo "$(tput setaf 2)Wake up neo....."
sleep 2s
echo "$(tput setaf 2)The Matrix has you......"
sleep 2s
reset
echo "$(tput setaf 2)Follow the white rabbit......"
sleep 2s
reset
cmatrix


This prints a message to terminal, but I want it look as though it's being typed, with a consistent delay between characters.







share|improve this question














I have a simple echo print out that I've added to my .bashrc:



echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
sleep 2s
echo "$(tput setaf 2)Wake up....."
sleep 2s
reset
echo "$(tput setaf 2)Wake up neo....."
sleep 2s
echo "$(tput setaf 2)The Matrix has you......"
sleep 2s
reset
echo "$(tput setaf 2)Follow the white rabbit......"
sleep 2s
reset
cmatrix


This prints a message to terminal, but I want it look as though it's being typed, with a consistent delay between characters.









share|improve this question













share|improve this question




share|improve this question








edited May 1 at 19:22









dessert

19.6k55594




19.6k55594










asked Apr 30 at 12:37









SimplySimplified

205415




205415







  • 1




    To be realistic I think you should have random typo thrown in with one or more back spaces to correct. For example whilst typing this comment I had to back space over "through" to correct it to "thrown". It makes it a more difficult question to answer but it makes it more realistic. If characters repeat at a steady pace of 30 CPS or 60 CPS it look less human. Certain keys are typed faster together, whilst other key combinations appear slower. Some sort of pattern matching of key combinations to speed is needed.
    – WinEunuuchs2Unix
    May 1 at 3:55







  • 2




    @WinEunuuchs2Unix I don't think this is still SimplySimplified. ;)
    – dessert
    May 1 at 10:28






  • 1




    See my answer here
    – Dennis Williamson
    May 1 at 23:34












  • 1




    To be realistic I think you should have random typo thrown in with one or more back spaces to correct. For example whilst typing this comment I had to back space over "through" to correct it to "thrown". It makes it a more difficult question to answer but it makes it more realistic. If characters repeat at a steady pace of 30 CPS or 60 CPS it look less human. Certain keys are typed faster together, whilst other key combinations appear slower. Some sort of pattern matching of key combinations to speed is needed.
    – WinEunuuchs2Unix
    May 1 at 3:55







  • 2




    @WinEunuuchs2Unix I don't think this is still SimplySimplified. ;)
    – dessert
    May 1 at 10:28






  • 1




    See my answer here
    – Dennis Williamson
    May 1 at 23:34







1




1




To be realistic I think you should have random typo thrown in with one or more back spaces to correct. For example whilst typing this comment I had to back space over "through" to correct it to "thrown". It makes it a more difficult question to answer but it makes it more realistic. If characters repeat at a steady pace of 30 CPS or 60 CPS it look less human. Certain keys are typed faster together, whilst other key combinations appear slower. Some sort of pattern matching of key combinations to speed is needed.
– WinEunuuchs2Unix
May 1 at 3:55





To be realistic I think you should have random typo thrown in with one or more back spaces to correct. For example whilst typing this comment I had to back space over "through" to correct it to "thrown". It makes it a more difficult question to answer but it makes it more realistic. If characters repeat at a steady pace of 30 CPS or 60 CPS it look less human. Certain keys are typed faster together, whilst other key combinations appear slower. Some sort of pattern matching of key combinations to speed is needed.
– WinEunuuchs2Unix
May 1 at 3:55





2




2




@WinEunuuchs2Unix I don't think this is still SimplySimplified. ;)
– dessert
May 1 at 10:28




@WinEunuuchs2Unix I don't think this is still SimplySimplified. ;)
– dessert
May 1 at 10:28




1




1




See my answer here
– Dennis Williamson
May 1 at 23:34




See my answer here
– Dennis Williamson
May 1 at 23:34










8 Answers
8






active

oldest

votes

















up vote
28
down vote



accepted










This does not work with Wayland; if you're using Ubuntu 17.10 and didn't change to using Xorg at login, this solution isn't for you.



You can use xdotool Install xdotool for that. If the delay between the keystrokes should be consistent, it's as simple as that:





xdotool type --delay 100 something


This types something with a delay of 100 milliseconds between each keystroke.




If the delay between the keystrokes should be random, let's say from 100 to 300 milliseconds, things get a bit more complicated:



$ text="some text"
for ((i=0;i<$#text;i++));
do
if [[ "$text:i:1" == " " ]];
then
echo -n "key space";
else
echo -n "key $text:i:1";
fi;
[[ $i < $(($#text-1)) ]] && echo -n " sleep 0.$(((RANDOM%3)+1)) ";
done | xdotool -


This for loop goes through every single letter of the string saved in variable text, printing either key <letter> or key space in the case of a space followed by sleep 0. and a random number between 1 and 3 (xdotool's sleep interprets the number as seconds). The whole output of the loop is then piped to xdotool, which prints the letters with the random delay in between. If you want to change the delay just change the (RANDOM%x)+y part, y being the lower and x-1+y the upper limit – for 0.2 to 0.5 seconds it would be (RANDOM%4)+2.



Note that this approach does not print the text, but rather type it exactly like the user would do, synthesizing single keypresses. In consequence the text gets typed into the currently focused window; if you change the focus part of the text will get typed in the newly focused window, which may or may not be what you want. In either case have a look at the other answers here, all of which are brilliant!






share|improve this answer





























    up vote
    24
    down vote













    I tried xdotool after reading @dessert's answer but couldn't get it to work for some reason. So I came up with this:



    while read line
    do
    grep -o . <<<$line | while read a
    do
    sleep 0.1
    echo -n "$a:- "
    done
    echo
    done


    Pipe your text into the above code and it will be printed like typed. You can also add randomness by replacing sleep 0.1 with sleep 0.$((RANDOM%3)).



    Extended version with fake typos



    This version will introduce a fake typo every now and then and correct it:



    while read line
    do
    # split single characters into lines
    grep -o . <<<$line | while read a
    do
    # short random delay between keystrokes
    sleep 0.$((RANDOM%3))
    # make fake typo every 30th keystroke
    if [[ $((RANDOM%30)) == 1 ]]
    then
    # print random character between a-z
    printf "\$(printf %o "$((RANDOM%26+97))")"
    # wait a bit and delete it again
    sleep 0.5; echo -ne 'b'; sleep 0.2
    fi
    # output a space, or $a if it is not null
    echo -n "$a:- "
    done
    echo
    done





    share|improve this answer






















    • I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
      – Digital Trauma
      May 1 at 15:57

















    up vote
    18
    down vote













    You mention a consistent delay between characters, but if you really want it to look like its being typed, the timing won't be perfectly consistent. To achieve this you can record your own typing with the script command and play it back with scriptreplay:





    $ script -t -c "sed d" script.out 2> script.timing
    Script started, file is script.out
    Wake up ...
    Wake up ...
    Wake up Neo ...
    Script done, file is script.out
    $
    $ scriptreplay script.timing script.out
    Wake up ...
    Wake up ...
    Wake up Neo ...

    $


    Recording is stopped by hitting CTRL-D.



    Passing the -t parameter to script instructs it also generate timing information, which I have redirected to the script.timing file. I have passed sed d as a command to script as this is simply a way to absorb input (and this record the keystrokes) with no side-effects.



    If you want to do all the tput/reset stuff too, you might want to do a script recording for each of your lines, and play them back, interleaved with the tput/reset commands.






    share|improve this answer



























      up vote
      11
      down vote













      Another possibility is using Demo Magic, or, to be more precise just the print function of this script collection, which basically amounts to



      #!/bin/bash

      . ./demo-magic.sh -w2

      p "this will look as if typed"


      Under the hood, this uses pv, which of course you can also use to directly get the desired effect, the basic form looks as follows:



      echo "this will look as if typed" | pv -qL 20





      share|improve this answer


















      • 1




        This usage of pv is just great.
        – Sebastian Stark
        Apr 30 at 20:03






      • 3




        No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
        – dr01
        May 1 at 8:43


















      up vote
      8
      down vote













      In line with my nickname I can offer another solution:



      echo "something" | 
      perl
      -MTime::HiRes=usleep
      -F''
      -e 'BEGIN =1 for (@F) print; usleep(100_000+rand(200_000)) '


      Looks weird, doesn't it?




      • -MTime::HiRes=usleep imports the function usleep (microsecond sleep) from the Time::HiRes module because the usual sleep accepts only integer seconds.


      • -F'' splits the given input into characters (the delimiter being empty '') and puts the characters in the array @F.


      • BEGIN =1 disables output buffering so each character is immediatly printed.


      • for (@F) print; usleep(100_000+rand(200_000)) just iterates over the characters

      • putting underscores in numbers is a common way to use some kind of thousands separators in Perl. They are simply ignored by Perl, so we can e.g. write 1_000 (==1000) or even 1_0_00 if we consider that easier to read.


      • rand() returns a random number between 0 and the given argument, so together this sleeps between 100,000 and 299,999 microseconds (0.1-0.3 seconds).





      share|improve this answer




















      • Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
        – dessert
        Apr 30 at 18:44






      • 1




        It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
        – PerlDuck
        Apr 30 at 18:46







      • 1




        This doesn't work without -a and -n
        – rrauenza
        May 2 at 17:35










      • @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
        – PerlDuck
        May 2 at 18:15










      • Ah, ok I was using 5.16, which is what is on CentOS7.
        – rrauenza
        May 2 at 18:41

















      up vote
      6
      down vote













      Another tool that might work, which does not depend on x11 or whatever, is asciicinema. It records everything you do in your terminal and lets you replay that as if it were a screen capture, only then it's purely ascii based! You might have to temporarily disable your prompt however for it to be purely visually clean. As other have pointed out, adding a consistent delay will not look natural, and typing it yourself might be one of the most natural looks you can achieve.



      After having recorded the text, you can do something like:



      $ asciinema play [your recording].cast; cmatrix





      share|improve this answer



























        up vote
        6
        down vote













        I'm surprised nobody's mentioned this yet, but you can accomplish this with stock tools and a loop:



        typeit() 
        local IFS=''
        while read -n1 c; do
        echo -n "$c"
        sleep .1
        done <<< "$1"



        It just loops over the input character by character and prints them out with a delay after each. The only tricky bit is that you have to set your IFS to an empty string so bash doesn't try to split away your spaces.



        This solution is dead-simple, so adding variable delays between characters, typos, whatever is super easy.



        EDIT (thanks, @dessert):
        If you want a slightly more natural interface, you could instead do



        typeit() 
        local IFS=''
        while read -n1 c; do
        echo -n "$c"
        sleep .1
        done <<< "$@"



        This would allow you to call the function as typeit foo bar rather than typeit 'foo bar'. Be aware that without quotes, the arguments are subject to bash's word splitting, so for example typeit foo<space><space>bar will print foo<space>bar. To preserve whitespace, use quotes.






        share|improve this answer






















        • Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
          – whereswalden
          May 1 at 15:12











        • +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
          – Sebastian Stark
          May 2 at 14:58

















        up vote
        5
        down vote













        First, "look as though it's being typed, with a consistent delay between characters..." is a little contradictory, as others have pointed out. Something being typed doesn't have a consistent delay. When you see something produced with an inconsistent delay, you'll get chills. "What's taken over my computer!!!??!?"



        Anyway...



        I have to make a shout out to expect, which should be available on most Linux distributions. Old School, I know, but- assuming it's installed- it could hardly be simpler:



        echo 'set send_human .1 .3 1 .05 2; send -h "The Matrix has you......n"' | expect -f /dev/stdin


        From the man page:




        The -h flag forces output to be sent (somewhat) like a human actually typing. Human-like delays appear between the characters. (The algorithm is based upon a Weibull distribution, with modifications to suit this particular application.) This output is controlled by the value of the variable "send_human"...




        See https://www.tcl.tk/man/expect5.31/expect.1.html






        share|improve this answer




















          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1030099%2fhow-to-print-text-in-the-terminal-as-if-its-being-typed%23new-answer', 'question_page');

          );

          Post as a guest






























          8 Answers
          8






          active

          oldest

          votes








          8 Answers
          8






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          28
          down vote



          accepted










          This does not work with Wayland; if you're using Ubuntu 17.10 and didn't change to using Xorg at login, this solution isn't for you.



          You can use xdotool Install xdotool for that. If the delay between the keystrokes should be consistent, it's as simple as that:





          xdotool type --delay 100 something


          This types something with a delay of 100 milliseconds between each keystroke.




          If the delay between the keystrokes should be random, let's say from 100 to 300 milliseconds, things get a bit more complicated:



          $ text="some text"
          for ((i=0;i<$#text;i++));
          do
          if [[ "$text:i:1" == " " ]];
          then
          echo -n "key space";
          else
          echo -n "key $text:i:1";
          fi;
          [[ $i < $(($#text-1)) ]] && echo -n " sleep 0.$(((RANDOM%3)+1)) ";
          done | xdotool -


          This for loop goes through every single letter of the string saved in variable text, printing either key <letter> or key space in the case of a space followed by sleep 0. and a random number between 1 and 3 (xdotool's sleep interprets the number as seconds). The whole output of the loop is then piped to xdotool, which prints the letters with the random delay in between. If you want to change the delay just change the (RANDOM%x)+y part, y being the lower and x-1+y the upper limit – for 0.2 to 0.5 seconds it would be (RANDOM%4)+2.



          Note that this approach does not print the text, but rather type it exactly like the user would do, synthesizing single keypresses. In consequence the text gets typed into the currently focused window; if you change the focus part of the text will get typed in the newly focused window, which may or may not be what you want. In either case have a look at the other answers here, all of which are brilliant!






          share|improve this answer


























            up vote
            28
            down vote



            accepted










            This does not work with Wayland; if you're using Ubuntu 17.10 and didn't change to using Xorg at login, this solution isn't for you.



            You can use xdotool Install xdotool for that. If the delay between the keystrokes should be consistent, it's as simple as that:





            xdotool type --delay 100 something


            This types something with a delay of 100 milliseconds between each keystroke.




            If the delay between the keystrokes should be random, let's say from 100 to 300 milliseconds, things get a bit more complicated:



            $ text="some text"
            for ((i=0;i<$#text;i++));
            do
            if [[ "$text:i:1" == " " ]];
            then
            echo -n "key space";
            else
            echo -n "key $text:i:1";
            fi;
            [[ $i < $(($#text-1)) ]] && echo -n " sleep 0.$(((RANDOM%3)+1)) ";
            done | xdotool -


            This for loop goes through every single letter of the string saved in variable text, printing either key <letter> or key space in the case of a space followed by sleep 0. and a random number between 1 and 3 (xdotool's sleep interprets the number as seconds). The whole output of the loop is then piped to xdotool, which prints the letters with the random delay in between. If you want to change the delay just change the (RANDOM%x)+y part, y being the lower and x-1+y the upper limit – for 0.2 to 0.5 seconds it would be (RANDOM%4)+2.



            Note that this approach does not print the text, but rather type it exactly like the user would do, synthesizing single keypresses. In consequence the text gets typed into the currently focused window; if you change the focus part of the text will get typed in the newly focused window, which may or may not be what you want. In either case have a look at the other answers here, all of which are brilliant!






            share|improve this answer
























              up vote
              28
              down vote



              accepted







              up vote
              28
              down vote



              accepted






              This does not work with Wayland; if you're using Ubuntu 17.10 and didn't change to using Xorg at login, this solution isn't for you.



              You can use xdotool Install xdotool for that. If the delay between the keystrokes should be consistent, it's as simple as that:





              xdotool type --delay 100 something


              This types something with a delay of 100 milliseconds between each keystroke.




              If the delay between the keystrokes should be random, let's say from 100 to 300 milliseconds, things get a bit more complicated:



              $ text="some text"
              for ((i=0;i<$#text;i++));
              do
              if [[ "$text:i:1" == " " ]];
              then
              echo -n "key space";
              else
              echo -n "key $text:i:1";
              fi;
              [[ $i < $(($#text-1)) ]] && echo -n " sleep 0.$(((RANDOM%3)+1)) ";
              done | xdotool -


              This for loop goes through every single letter of the string saved in variable text, printing either key <letter> or key space in the case of a space followed by sleep 0. and a random number between 1 and 3 (xdotool's sleep interprets the number as seconds). The whole output of the loop is then piped to xdotool, which prints the letters with the random delay in between. If you want to change the delay just change the (RANDOM%x)+y part, y being the lower and x-1+y the upper limit – for 0.2 to 0.5 seconds it would be (RANDOM%4)+2.



              Note that this approach does not print the text, but rather type it exactly like the user would do, synthesizing single keypresses. In consequence the text gets typed into the currently focused window; if you change the focus part of the text will get typed in the newly focused window, which may or may not be what you want. In either case have a look at the other answers here, all of which are brilliant!






              share|improve this answer














              This does not work with Wayland; if you're using Ubuntu 17.10 and didn't change to using Xorg at login, this solution isn't for you.



              You can use xdotool Install xdotool for that. If the delay between the keystrokes should be consistent, it's as simple as that:





              xdotool type --delay 100 something


              This types something with a delay of 100 milliseconds between each keystroke.




              If the delay between the keystrokes should be random, let's say from 100 to 300 milliseconds, things get a bit more complicated:



              $ text="some text"
              for ((i=0;i<$#text;i++));
              do
              if [[ "$text:i:1" == " " ]];
              then
              echo -n "key space";
              else
              echo -n "key $text:i:1";
              fi;
              [[ $i < $(($#text-1)) ]] && echo -n " sleep 0.$(((RANDOM%3)+1)) ";
              done | xdotool -


              This for loop goes through every single letter of the string saved in variable text, printing either key <letter> or key space in the case of a space followed by sleep 0. and a random number between 1 and 3 (xdotool's sleep interprets the number as seconds). The whole output of the loop is then piped to xdotool, which prints the letters with the random delay in between. If you want to change the delay just change the (RANDOM%x)+y part, y being the lower and x-1+y the upper limit – for 0.2 to 0.5 seconds it would be (RANDOM%4)+2.



              Note that this approach does not print the text, but rather type it exactly like the user would do, synthesizing single keypresses. In consequence the text gets typed into the currently focused window; if you change the focus part of the text will get typed in the newly focused window, which may or may not be what you want. In either case have a look at the other answers here, all of which are brilliant!







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 1 at 7:33

























              answered Apr 30 at 12:45









              dessert

              19.6k55594




              19.6k55594






















                  up vote
                  24
                  down vote













                  I tried xdotool after reading @dessert's answer but couldn't get it to work for some reason. So I came up with this:



                  while read line
                  do
                  grep -o . <<<$line | while read a
                  do
                  sleep 0.1
                  echo -n "$a:- "
                  done
                  echo
                  done


                  Pipe your text into the above code and it will be printed like typed. You can also add randomness by replacing sleep 0.1 with sleep 0.$((RANDOM%3)).



                  Extended version with fake typos



                  This version will introduce a fake typo every now and then and correct it:



                  while read line
                  do
                  # split single characters into lines
                  grep -o . <<<$line | while read a
                  do
                  # short random delay between keystrokes
                  sleep 0.$((RANDOM%3))
                  # make fake typo every 30th keystroke
                  if [[ $((RANDOM%30)) == 1 ]]
                  then
                  # print random character between a-z
                  printf "\$(printf %o "$((RANDOM%26+97))")"
                  # wait a bit and delete it again
                  sleep 0.5; echo -ne 'b'; sleep 0.2
                  fi
                  # output a space, or $a if it is not null
                  echo -n "$a:- "
                  done
                  echo
                  done





                  share|improve this answer






















                  • I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
                    – Digital Trauma
                    May 1 at 15:57














                  up vote
                  24
                  down vote













                  I tried xdotool after reading @dessert's answer but couldn't get it to work for some reason. So I came up with this:



                  while read line
                  do
                  grep -o . <<<$line | while read a
                  do
                  sleep 0.1
                  echo -n "$a:- "
                  done
                  echo
                  done


                  Pipe your text into the above code and it will be printed like typed. You can also add randomness by replacing sleep 0.1 with sleep 0.$((RANDOM%3)).



                  Extended version with fake typos



                  This version will introduce a fake typo every now and then and correct it:



                  while read line
                  do
                  # split single characters into lines
                  grep -o . <<<$line | while read a
                  do
                  # short random delay between keystrokes
                  sleep 0.$((RANDOM%3))
                  # make fake typo every 30th keystroke
                  if [[ $((RANDOM%30)) == 1 ]]
                  then
                  # print random character between a-z
                  printf "\$(printf %o "$((RANDOM%26+97))")"
                  # wait a bit and delete it again
                  sleep 0.5; echo -ne 'b'; sleep 0.2
                  fi
                  # output a space, or $a if it is not null
                  echo -n "$a:- "
                  done
                  echo
                  done





                  share|improve this answer






















                  • I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
                    – Digital Trauma
                    May 1 at 15:57












                  up vote
                  24
                  down vote










                  up vote
                  24
                  down vote









                  I tried xdotool after reading @dessert's answer but couldn't get it to work for some reason. So I came up with this:



                  while read line
                  do
                  grep -o . <<<$line | while read a
                  do
                  sleep 0.1
                  echo -n "$a:- "
                  done
                  echo
                  done


                  Pipe your text into the above code and it will be printed like typed. You can also add randomness by replacing sleep 0.1 with sleep 0.$((RANDOM%3)).



                  Extended version with fake typos



                  This version will introduce a fake typo every now and then and correct it:



                  while read line
                  do
                  # split single characters into lines
                  grep -o . <<<$line | while read a
                  do
                  # short random delay between keystrokes
                  sleep 0.$((RANDOM%3))
                  # make fake typo every 30th keystroke
                  if [[ $((RANDOM%30)) == 1 ]]
                  then
                  # print random character between a-z
                  printf "\$(printf %o "$((RANDOM%26+97))")"
                  # wait a bit and delete it again
                  sleep 0.5; echo -ne 'b'; sleep 0.2
                  fi
                  # output a space, or $a if it is not null
                  echo -n "$a:- "
                  done
                  echo
                  done





                  share|improve this answer














                  I tried xdotool after reading @dessert's answer but couldn't get it to work for some reason. So I came up with this:



                  while read line
                  do
                  grep -o . <<<$line | while read a
                  do
                  sleep 0.1
                  echo -n "$a:- "
                  done
                  echo
                  done


                  Pipe your text into the above code and it will be printed like typed. You can also add randomness by replacing sleep 0.1 with sleep 0.$((RANDOM%3)).



                  Extended version with fake typos



                  This version will introduce a fake typo every now and then and correct it:



                  while read line
                  do
                  # split single characters into lines
                  grep -o . <<<$line | while read a
                  do
                  # short random delay between keystrokes
                  sleep 0.$((RANDOM%3))
                  # make fake typo every 30th keystroke
                  if [[ $((RANDOM%30)) == 1 ]]
                  then
                  # print random character between a-z
                  printf "\$(printf %o "$((RANDOM%26+97))")"
                  # wait a bit and delete it again
                  sleep 0.5; echo -ne 'b'; sleep 0.2
                  fi
                  # output a space, or $a if it is not null
                  echo -n "$a:- "
                  done
                  echo
                  done






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 1 at 12:13

























                  answered Apr 30 at 14:53









                  Sebastian Stark

                  4,663938




                  4,663938











                  • I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
                    – Digital Trauma
                    May 1 at 15:57
















                  • I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
                    – Digital Trauma
                    May 1 at 15:57















                  I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
                  – Digital Trauma
                  May 1 at 15:57




                  I think I would do this instead: while IFS= read -r line; do for (( i = 0; i < $#line; i++ )); do sleep 0.1; printf "%s" "$line:i:1"; done; echo; done (replace ; with newlines and good indentation as necessary). The IFS= read -r and printf "%s" ensure that whitespace and special characters are not treated any differently. And the grep on each line to split into characters is unnecessary - just a for loop over each char in the line is sufficient.
                  – Digital Trauma
                  May 1 at 15:57










                  up vote
                  18
                  down vote













                  You mention a consistent delay between characters, but if you really want it to look like its being typed, the timing won't be perfectly consistent. To achieve this you can record your own typing with the script command and play it back with scriptreplay:





                  $ script -t -c "sed d" script.out 2> script.timing
                  Script started, file is script.out
                  Wake up ...
                  Wake up ...
                  Wake up Neo ...
                  Script done, file is script.out
                  $
                  $ scriptreplay script.timing script.out
                  Wake up ...
                  Wake up ...
                  Wake up Neo ...

                  $


                  Recording is stopped by hitting CTRL-D.



                  Passing the -t parameter to script instructs it also generate timing information, which I have redirected to the script.timing file. I have passed sed d as a command to script as this is simply a way to absorb input (and this record the keystrokes) with no side-effects.



                  If you want to do all the tput/reset stuff too, you might want to do a script recording for each of your lines, and play them back, interleaved with the tput/reset commands.






                  share|improve this answer
























                    up vote
                    18
                    down vote













                    You mention a consistent delay between characters, but if you really want it to look like its being typed, the timing won't be perfectly consistent. To achieve this you can record your own typing with the script command and play it back with scriptreplay:





                    $ script -t -c "sed d" script.out 2> script.timing
                    Script started, file is script.out
                    Wake up ...
                    Wake up ...
                    Wake up Neo ...
                    Script done, file is script.out
                    $
                    $ scriptreplay script.timing script.out
                    Wake up ...
                    Wake up ...
                    Wake up Neo ...

                    $


                    Recording is stopped by hitting CTRL-D.



                    Passing the -t parameter to script instructs it also generate timing information, which I have redirected to the script.timing file. I have passed sed d as a command to script as this is simply a way to absorb input (and this record the keystrokes) with no side-effects.



                    If you want to do all the tput/reset stuff too, you might want to do a script recording for each of your lines, and play them back, interleaved with the tput/reset commands.






                    share|improve this answer






















                      up vote
                      18
                      down vote










                      up vote
                      18
                      down vote









                      You mention a consistent delay between characters, but if you really want it to look like its being typed, the timing won't be perfectly consistent. To achieve this you can record your own typing with the script command and play it back with scriptreplay:





                      $ script -t -c "sed d" script.out 2> script.timing
                      Script started, file is script.out
                      Wake up ...
                      Wake up ...
                      Wake up Neo ...
                      Script done, file is script.out
                      $
                      $ scriptreplay script.timing script.out
                      Wake up ...
                      Wake up ...
                      Wake up Neo ...

                      $


                      Recording is stopped by hitting CTRL-D.



                      Passing the -t parameter to script instructs it also generate timing information, which I have redirected to the script.timing file. I have passed sed d as a command to script as this is simply a way to absorb input (and this record the keystrokes) with no side-effects.



                      If you want to do all the tput/reset stuff too, you might want to do a script recording for each of your lines, and play them back, interleaved with the tput/reset commands.






                      share|improve this answer












                      You mention a consistent delay between characters, but if you really want it to look like its being typed, the timing won't be perfectly consistent. To achieve this you can record your own typing with the script command and play it back with scriptreplay:





                      $ script -t -c "sed d" script.out 2> script.timing
                      Script started, file is script.out
                      Wake up ...
                      Wake up ...
                      Wake up Neo ...
                      Script done, file is script.out
                      $
                      $ scriptreplay script.timing script.out
                      Wake up ...
                      Wake up ...
                      Wake up Neo ...

                      $


                      Recording is stopped by hitting CTRL-D.



                      Passing the -t parameter to script instructs it also generate timing information, which I have redirected to the script.timing file. I have passed sed d as a command to script as this is simply a way to absorb input (and this record the keystrokes) with no side-effects.



                      If you want to do all the tput/reset stuff too, you might want to do a script recording for each of your lines, and play them back, interleaved with the tput/reset commands.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 30 at 17:45









                      Digital Trauma

                      1,495517




                      1,495517




















                          up vote
                          11
                          down vote













                          Another possibility is using Demo Magic, or, to be more precise just the print function of this script collection, which basically amounts to



                          #!/bin/bash

                          . ./demo-magic.sh -w2

                          p "this will look as if typed"


                          Under the hood, this uses pv, which of course you can also use to directly get the desired effect, the basic form looks as follows:



                          echo "this will look as if typed" | pv -qL 20





                          share|improve this answer


















                          • 1




                            This usage of pv is just great.
                            – Sebastian Stark
                            Apr 30 at 20:03






                          • 3




                            No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
                            – dr01
                            May 1 at 8:43















                          up vote
                          11
                          down vote













                          Another possibility is using Demo Magic, or, to be more precise just the print function of this script collection, which basically amounts to



                          #!/bin/bash

                          . ./demo-magic.sh -w2

                          p "this will look as if typed"


                          Under the hood, this uses pv, which of course you can also use to directly get the desired effect, the basic form looks as follows:



                          echo "this will look as if typed" | pv -qL 20





                          share|improve this answer


















                          • 1




                            This usage of pv is just great.
                            – Sebastian Stark
                            Apr 30 at 20:03






                          • 3




                            No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
                            – dr01
                            May 1 at 8:43













                          up vote
                          11
                          down vote










                          up vote
                          11
                          down vote









                          Another possibility is using Demo Magic, or, to be more precise just the print function of this script collection, which basically amounts to



                          #!/bin/bash

                          . ./demo-magic.sh -w2

                          p "this will look as if typed"


                          Under the hood, this uses pv, which of course you can also use to directly get the desired effect, the basic form looks as follows:



                          echo "this will look as if typed" | pv -qL 20





                          share|improve this answer














                          Another possibility is using Demo Magic, or, to be more precise just the print function of this script collection, which basically amounts to



                          #!/bin/bash

                          . ./demo-magic.sh -w2

                          p "this will look as if typed"


                          Under the hood, this uses pv, which of course you can also use to directly get the desired effect, the basic form looks as follows:



                          echo "this will look as if typed" | pv -qL 20






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited May 1 at 4:09

























                          answered Apr 30 at 19:51









                          godfatherofpolka

                          2115




                          2115







                          • 1




                            This usage of pv is just great.
                            – Sebastian Stark
                            Apr 30 at 20:03






                          • 3




                            No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
                            – dr01
                            May 1 at 8:43













                          • 1




                            This usage of pv is just great.
                            – Sebastian Stark
                            Apr 30 at 20:03






                          • 3




                            No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
                            – dr01
                            May 1 at 8:43








                          1




                          1




                          This usage of pv is just great.
                          – Sebastian Stark
                          Apr 30 at 20:03




                          This usage of pv is just great.
                          – Sebastian Stark
                          Apr 30 at 20:03




                          3




                          3




                          No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
                          – dr01
                          May 1 at 8:43





                          No need to pipe echo to pv, just use pv -qL20 <<< "Hello world" if your shell supports herestrings.
                          – dr01
                          May 1 at 8:43











                          up vote
                          8
                          down vote













                          In line with my nickname I can offer another solution:



                          echo "something" | 
                          perl
                          -MTime::HiRes=usleep
                          -F''
                          -e 'BEGIN =1 for (@F) print; usleep(100_000+rand(200_000)) '


                          Looks weird, doesn't it?




                          • -MTime::HiRes=usleep imports the function usleep (microsecond sleep) from the Time::HiRes module because the usual sleep accepts only integer seconds.


                          • -F'' splits the given input into characters (the delimiter being empty '') and puts the characters in the array @F.


                          • BEGIN =1 disables output buffering so each character is immediatly printed.


                          • for (@F) print; usleep(100_000+rand(200_000)) just iterates over the characters

                          • putting underscores in numbers is a common way to use some kind of thousands separators in Perl. They are simply ignored by Perl, so we can e.g. write 1_000 (==1000) or even 1_0_00 if we consider that easier to read.


                          • rand() returns a random number between 0 and the given argument, so together this sleeps between 100,000 and 299,999 microseconds (0.1-0.3 seconds).





                          share|improve this answer




















                          • Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
                            – dessert
                            Apr 30 at 18:44






                          • 1




                            It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
                            – PerlDuck
                            Apr 30 at 18:46







                          • 1




                            This doesn't work without -a and -n
                            – rrauenza
                            May 2 at 17:35










                          • @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
                            – PerlDuck
                            May 2 at 18:15










                          • Ah, ok I was using 5.16, which is what is on CentOS7.
                            – rrauenza
                            May 2 at 18:41














                          up vote
                          8
                          down vote













                          In line with my nickname I can offer another solution:



                          echo "something" | 
                          perl
                          -MTime::HiRes=usleep
                          -F''
                          -e 'BEGIN =1 for (@F) print; usleep(100_000+rand(200_000)) '


                          Looks weird, doesn't it?




                          • -MTime::HiRes=usleep imports the function usleep (microsecond sleep) from the Time::HiRes module because the usual sleep accepts only integer seconds.


                          • -F'' splits the given input into characters (the delimiter being empty '') and puts the characters in the array @F.


                          • BEGIN =1 disables output buffering so each character is immediatly printed.


                          • for (@F) print; usleep(100_000+rand(200_000)) just iterates over the characters

                          • putting underscores in numbers is a common way to use some kind of thousands separators in Perl. They are simply ignored by Perl, so we can e.g. write 1_000 (==1000) or even 1_0_00 if we consider that easier to read.


                          • rand() returns a random number between 0 and the given argument, so together this sleeps between 100,000 and 299,999 microseconds (0.1-0.3 seconds).





                          share|improve this answer




















                          • Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
                            – dessert
                            Apr 30 at 18:44






                          • 1




                            It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
                            – PerlDuck
                            Apr 30 at 18:46







                          • 1




                            This doesn't work without -a and -n
                            – rrauenza
                            May 2 at 17:35










                          • @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
                            – PerlDuck
                            May 2 at 18:15










                          • Ah, ok I was using 5.16, which is what is on CentOS7.
                            – rrauenza
                            May 2 at 18:41












                          up vote
                          8
                          down vote










                          up vote
                          8
                          down vote









                          In line with my nickname I can offer another solution:



                          echo "something" | 
                          perl
                          -MTime::HiRes=usleep
                          -F''
                          -e 'BEGIN =1 for (@F) print; usleep(100_000+rand(200_000)) '


                          Looks weird, doesn't it?




                          • -MTime::HiRes=usleep imports the function usleep (microsecond sleep) from the Time::HiRes module because the usual sleep accepts only integer seconds.


                          • -F'' splits the given input into characters (the delimiter being empty '') and puts the characters in the array @F.


                          • BEGIN =1 disables output buffering so each character is immediatly printed.


                          • for (@F) print; usleep(100_000+rand(200_000)) just iterates over the characters

                          • putting underscores in numbers is a common way to use some kind of thousands separators in Perl. They are simply ignored by Perl, so we can e.g. write 1_000 (==1000) or even 1_0_00 if we consider that easier to read.


                          • rand() returns a random number between 0 and the given argument, so together this sleeps between 100,000 and 299,999 microseconds (0.1-0.3 seconds).





                          share|improve this answer












                          In line with my nickname I can offer another solution:



                          echo "something" | 
                          perl
                          -MTime::HiRes=usleep
                          -F''
                          -e 'BEGIN =1 for (@F) print; usleep(100_000+rand(200_000)) '


                          Looks weird, doesn't it?




                          • -MTime::HiRes=usleep imports the function usleep (microsecond sleep) from the Time::HiRes module because the usual sleep accepts only integer seconds.


                          • -F'' splits the given input into characters (the delimiter being empty '') and puts the characters in the array @F.


                          • BEGIN =1 disables output buffering so each character is immediatly printed.


                          • for (@F) print; usleep(100_000+rand(200_000)) just iterates over the characters

                          • putting underscores in numbers is a common way to use some kind of thousands separators in Perl. They are simply ignored by Perl, so we can e.g. write 1_000 (==1000) or even 1_0_00 if we consider that easier to read.


                          • rand() returns a random number between 0 and the given argument, so together this sleeps between 100,000 and 299,999 microseconds (0.1-0.3 seconds).






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 30 at 17:20









                          PerlDuck

                          3,72411030




                          3,72411030











                          • Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
                            – dessert
                            Apr 30 at 18:44






                          • 1




                            It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
                            – PerlDuck
                            Apr 30 at 18:46







                          • 1




                            This doesn't work without -a and -n
                            – rrauenza
                            May 2 at 17:35










                          • @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
                            – PerlDuck
                            May 2 at 18:15










                          • Ah, ok I was using 5.16, which is what is on CentOS7.
                            – rrauenza
                            May 2 at 18:41
















                          • Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
                            – dessert
                            Apr 30 at 18:44






                          • 1




                            It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
                            – PerlDuck
                            Apr 30 at 18:46







                          • 1




                            This doesn't work without -a and -n
                            – rrauenza
                            May 2 at 17:35










                          • @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
                            – PerlDuck
                            May 2 at 18:15










                          • Ah, ok I was using 5.16, which is what is on CentOS7.
                            – rrauenza
                            May 2 at 18:41















                          Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
                          – dessert
                          Apr 30 at 18:44




                          Just out of curiosity: Does rand() return a number from 0 to the argument (100k to 300k in your example) or between them (100k+1 to 300k-1 in your example)?
                          – dessert
                          Apr 30 at 18:44




                          1




                          1




                          It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
                          – PerlDuck
                          Apr 30 at 18:46





                          It returns a number in the interval [0,200k), i.e. including 0 but excluding 200k. The exact behaviour is documented here: "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.)"
                          – PerlDuck
                          Apr 30 at 18:46





                          1




                          1




                          This doesn't work without -a and -n
                          – rrauenza
                          May 2 at 17:35




                          This doesn't work without -a and -n
                          – rrauenza
                          May 2 at 17:35












                          @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
                          – PerlDuck
                          May 2 at 18:15




                          @rrauenza Since Perl 5.20 it does. -F implies -a and -a implies -n.
                          – PerlDuck
                          May 2 at 18:15












                          Ah, ok I was using 5.16, which is what is on CentOS7.
                          – rrauenza
                          May 2 at 18:41




                          Ah, ok I was using 5.16, which is what is on CentOS7.
                          – rrauenza
                          May 2 at 18:41










                          up vote
                          6
                          down vote













                          Another tool that might work, which does not depend on x11 or whatever, is asciicinema. It records everything you do in your terminal and lets you replay that as if it were a screen capture, only then it's purely ascii based! You might have to temporarily disable your prompt however for it to be purely visually clean. As other have pointed out, adding a consistent delay will not look natural, and typing it yourself might be one of the most natural looks you can achieve.



                          After having recorded the text, you can do something like:



                          $ asciinema play [your recording].cast; cmatrix





                          share|improve this answer
























                            up vote
                            6
                            down vote













                            Another tool that might work, which does not depend on x11 or whatever, is asciicinema. It records everything you do in your terminal and lets you replay that as if it were a screen capture, only then it's purely ascii based! You might have to temporarily disable your prompt however for it to be purely visually clean. As other have pointed out, adding a consistent delay will not look natural, and typing it yourself might be one of the most natural looks you can achieve.



                            After having recorded the text, you can do something like:



                            $ asciinema play [your recording].cast; cmatrix





                            share|improve this answer






















                              up vote
                              6
                              down vote










                              up vote
                              6
                              down vote









                              Another tool that might work, which does not depend on x11 or whatever, is asciicinema. It records everything you do in your terminal and lets you replay that as if it were a screen capture, only then it's purely ascii based! You might have to temporarily disable your prompt however for it to be purely visually clean. As other have pointed out, adding a consistent delay will not look natural, and typing it yourself might be one of the most natural looks you can achieve.



                              After having recorded the text, you can do something like:



                              $ asciinema play [your recording].cast; cmatrix





                              share|improve this answer












                              Another tool that might work, which does not depend on x11 or whatever, is asciicinema. It records everything you do in your terminal and lets you replay that as if it were a screen capture, only then it's purely ascii based! You might have to temporarily disable your prompt however for it to be purely visually clean. As other have pointed out, adding a consistent delay will not look natural, and typing it yourself might be one of the most natural looks you can achieve.



                              After having recorded the text, you can do something like:



                              $ asciinema play [your recording].cast; cmatrix






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered May 2 at 13:31









                              rien333

                              1612




                              1612




















                                  up vote
                                  6
                                  down vote













                                  I'm surprised nobody's mentioned this yet, but you can accomplish this with stock tools and a loop:



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$1"



                                  It just loops over the input character by character and prints them out with a delay after each. The only tricky bit is that you have to set your IFS to an empty string so bash doesn't try to split away your spaces.



                                  This solution is dead-simple, so adding variable delays between characters, typos, whatever is super easy.



                                  EDIT (thanks, @dessert):
                                  If you want a slightly more natural interface, you could instead do



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$@"



                                  This would allow you to call the function as typeit foo bar rather than typeit 'foo bar'. Be aware that without quotes, the arguments are subject to bash's word splitting, so for example typeit foo<space><space>bar will print foo<space>bar. To preserve whitespace, use quotes.






                                  share|improve this answer






















                                  • Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
                                    – whereswalden
                                    May 1 at 15:12











                                  • +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
                                    – Sebastian Stark
                                    May 2 at 14:58














                                  up vote
                                  6
                                  down vote













                                  I'm surprised nobody's mentioned this yet, but you can accomplish this with stock tools and a loop:



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$1"



                                  It just loops over the input character by character and prints them out with a delay after each. The only tricky bit is that you have to set your IFS to an empty string so bash doesn't try to split away your spaces.



                                  This solution is dead-simple, so adding variable delays between characters, typos, whatever is super easy.



                                  EDIT (thanks, @dessert):
                                  If you want a slightly more natural interface, you could instead do



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$@"



                                  This would allow you to call the function as typeit foo bar rather than typeit 'foo bar'. Be aware that without quotes, the arguments are subject to bash's word splitting, so for example typeit foo<space><space>bar will print foo<space>bar. To preserve whitespace, use quotes.






                                  share|improve this answer






















                                  • Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
                                    – whereswalden
                                    May 1 at 15:12











                                  • +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
                                    – Sebastian Stark
                                    May 2 at 14:58












                                  up vote
                                  6
                                  down vote










                                  up vote
                                  6
                                  down vote









                                  I'm surprised nobody's mentioned this yet, but you can accomplish this with stock tools and a loop:



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$1"



                                  It just loops over the input character by character and prints them out with a delay after each. The only tricky bit is that you have to set your IFS to an empty string so bash doesn't try to split away your spaces.



                                  This solution is dead-simple, so adding variable delays between characters, typos, whatever is super easy.



                                  EDIT (thanks, @dessert):
                                  If you want a slightly more natural interface, you could instead do



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$@"



                                  This would allow you to call the function as typeit foo bar rather than typeit 'foo bar'. Be aware that without quotes, the arguments are subject to bash's word splitting, so for example typeit foo<space><space>bar will print foo<space>bar. To preserve whitespace, use quotes.






                                  share|improve this answer














                                  I'm surprised nobody's mentioned this yet, but you can accomplish this with stock tools and a loop:



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$1"



                                  It just loops over the input character by character and prints them out with a delay after each. The only tricky bit is that you have to set your IFS to an empty string so bash doesn't try to split away your spaces.



                                  This solution is dead-simple, so adding variable delays between characters, typos, whatever is super easy.



                                  EDIT (thanks, @dessert):
                                  If you want a slightly more natural interface, you could instead do



                                  typeit() 
                                  local IFS=''
                                  while read -n1 c; do
                                  echo -n "$c"
                                  sleep .1
                                  done <<< "$@"



                                  This would allow you to call the function as typeit foo bar rather than typeit 'foo bar'. Be aware that without quotes, the arguments are subject to bash's word splitting, so for example typeit foo<space><space>bar will print foo<space>bar. To preserve whitespace, use quotes.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited May 2 at 14:47

























                                  answered May 1 at 2:04









                                  whereswalden

                                  1614




                                  1614











                                  • Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
                                    – whereswalden
                                    May 1 at 15:12











                                  • +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
                                    – Sebastian Stark
                                    May 2 at 14:58
















                                  • Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
                                    – whereswalden
                                    May 1 at 15:12











                                  • +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
                                    – Sebastian Stark
                                    May 2 at 14:58















                                  Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
                                  – whereswalden
                                  May 1 at 15:12





                                  Good suggestion, though it should be noted that word-splitting applies. For example, typeit foo<space>bar will result in foo bar, whereas typeit foo<space><space>bar will also result in foo bar. You've got to quote it to make sure it's verbatim. @dessert feel free to suggest an edit. I can do it myself, but I want to give you the chance to get credit for it.
                                  – whereswalden
                                  May 1 at 15:12













                                  +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
                                  – Sebastian Stark
                                  May 2 at 14:58




                                  +1 for teaching me about read -n1 (which, btw. is read -k1 in zsh)
                                  – Sebastian Stark
                                  May 2 at 14:58










                                  up vote
                                  5
                                  down vote













                                  First, "look as though it's being typed, with a consistent delay between characters..." is a little contradictory, as others have pointed out. Something being typed doesn't have a consistent delay. When you see something produced with an inconsistent delay, you'll get chills. "What's taken over my computer!!!??!?"



                                  Anyway...



                                  I have to make a shout out to expect, which should be available on most Linux distributions. Old School, I know, but- assuming it's installed- it could hardly be simpler:



                                  echo 'set send_human .1 .3 1 .05 2; send -h "The Matrix has you......n"' | expect -f /dev/stdin


                                  From the man page:




                                  The -h flag forces output to be sent (somewhat) like a human actually typing. Human-like delays appear between the characters. (The algorithm is based upon a Weibull distribution, with modifications to suit this particular application.) This output is controlled by the value of the variable "send_human"...




                                  See https://www.tcl.tk/man/expect5.31/expect.1.html






                                  share|improve this answer
























                                    up vote
                                    5
                                    down vote













                                    First, "look as though it's being typed, with a consistent delay between characters..." is a little contradictory, as others have pointed out. Something being typed doesn't have a consistent delay. When you see something produced with an inconsistent delay, you'll get chills. "What's taken over my computer!!!??!?"



                                    Anyway...



                                    I have to make a shout out to expect, which should be available on most Linux distributions. Old School, I know, but- assuming it's installed- it could hardly be simpler:



                                    echo 'set send_human .1 .3 1 .05 2; send -h "The Matrix has you......n"' | expect -f /dev/stdin


                                    From the man page:




                                    The -h flag forces output to be sent (somewhat) like a human actually typing. Human-like delays appear between the characters. (The algorithm is based upon a Weibull distribution, with modifications to suit this particular application.) This output is controlled by the value of the variable "send_human"...




                                    See https://www.tcl.tk/man/expect5.31/expect.1.html






                                    share|improve this answer






















                                      up vote
                                      5
                                      down vote










                                      up vote
                                      5
                                      down vote









                                      First, "look as though it's being typed, with a consistent delay between characters..." is a little contradictory, as others have pointed out. Something being typed doesn't have a consistent delay. When you see something produced with an inconsistent delay, you'll get chills. "What's taken over my computer!!!??!?"



                                      Anyway...



                                      I have to make a shout out to expect, which should be available on most Linux distributions. Old School, I know, but- assuming it's installed- it could hardly be simpler:



                                      echo 'set send_human .1 .3 1 .05 2; send -h "The Matrix has you......n"' | expect -f /dev/stdin


                                      From the man page:




                                      The -h flag forces output to be sent (somewhat) like a human actually typing. Human-like delays appear between the characters. (The algorithm is based upon a Weibull distribution, with modifications to suit this particular application.) This output is controlled by the value of the variable "send_human"...




                                      See https://www.tcl.tk/man/expect5.31/expect.1.html






                                      share|improve this answer












                                      First, "look as though it's being typed, with a consistent delay between characters..." is a little contradictory, as others have pointed out. Something being typed doesn't have a consistent delay. When you see something produced with an inconsistent delay, you'll get chills. "What's taken over my computer!!!??!?"



                                      Anyway...



                                      I have to make a shout out to expect, which should be available on most Linux distributions. Old School, I know, but- assuming it's installed- it could hardly be simpler:



                                      echo 'set send_human .1 .3 1 .05 2; send -h "The Matrix has you......n"' | expect -f /dev/stdin


                                      From the man page:




                                      The -h flag forces output to be sent (somewhat) like a human actually typing. Human-like delays appear between the characters. (The algorithm is based upon a Weibull distribution, with modifications to suit this particular application.) This output is controlled by the value of the variable "send_human"...




                                      See https://www.tcl.tk/man/expect5.31/expect.1.html







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 2 at 12:53









                                      Mike S

                                      25927




                                      25927






















                                           

                                          draft saved


                                          draft discarded


























                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1030099%2fhow-to-print-text-in-the-terminal-as-if-its-being-typed%23new-answer', 'question_page');

                                          );

                                          Post as a guest













































































                                          Popular posts from this blog

                                          pylint3 and pip3 broken

                                          Missing snmpget and snmpwalk

                                          How to enroll fingerprints to Ubuntu 17.10 with VFS491