[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

unix

how to display a string character by character on the screeen?
0
a_puru_r
Asked:
a_puru_r
  • 3
  • 2
1 Solution
 
ozoCommented:
fflush
0
 
expert99121199Commented:
This little script will echo the letters in a word one at a time with a one second pause between each letter.  It is efficient because it is all in shell (except sleep, which can be removed).  It works by executing the program with the word (STRING) you wish to display provided on the command line.  As written the word must be all lower case with no spaces.  You should be able to figure out how to handle mixed case easily.  I hope this is what you were looking for.

expert99

#!/bin/sh
OLDIFS="$IFS"
STRING="$*"

while [ "$STRING" != "" ]
do
        for C in a b c d e f g h i j k l m n o p q r s t u v w x y z
        do
                IFS="$C"
                \s\e\t -- $STRING
                IFS="$OLDIFS"
                case "$STRING" in
                        "$C"?*)echo "$C\c"
                        sleep 1
                        case "$#" in
                                1)STRING="$1";;
                                2)STRING="$1$C$2";;
                                3)STRING="$1$C$2$C$3";;
                                4)STRING="$1$C$2$C$3$C$4";;
                        esac
                        ;;
                        "$C")echo "$C"
                        break 2;;
                esac
        done
done
0
 
ozoCommented:
As written the word must also have no repeated letters
0
 
expert99121199Commented:
ozo is correct!  Let me know if this is what you had in mind and I will enable it to handle Mississippi - or other words with repeating letters.  This design cannot be made to handle arbitrary strings - it is for words, spaces, numbers, etc.  Punctuation will also present a challenge.  Still, it may be what you are looking for.

expert99
0
 
ozoCommented:
perl -e '$|=1; $_=shift; for( /./g ){ print; sleep 1 }' 'Mississippi - or other words with repeating letters'
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now