LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-25-2010, 06:23 PM   #1
RavhisingRickRude
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Rep: Reputation: 0
Newbie needs help with script


Hello Everyone,

Im a linux newbie and Im trying to create a very basic script that will echo a question like "What is your name?" but i would like for the question not to echo the whole sentence at once but word by word or even character by character, in other words to give the illusion that the computer is actually typing the question.I hope this makes sense. I played around with the sleep command, but it will echo each word in a different line rather than the same line. Is there a way to do this? Thank

- RRR

Last edited by RavhisingRickRude; 12-28-2010 at 01:10 AM.
 
Old 12-25-2010, 06:53 PM   #2
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
Code:
echo -n
Will echo without the newline. Linux has 'manpages'; you can go
Code:
man command
to find info about a particular command. Failing knowing the command you can go:
Code:
man -k keyword
to find all the manpages containing the keyword.

HTH

Last edited by barriehie; 12-25-2010 at 06:53 PM. Reason: typo.
 
Old 12-25-2010, 07:35 PM   #3
speck
Member
 
Registered: Nov 2001
Location: US
Distribution: Slackware 14.2
Posts: 375

Rep: Reputation: 115Reputation: 115
You could do this with an Expect script. There should already an Expect script named "beer.exp" installed on your computer (if Expect is installed) that will show you an example of how to do it.
 
Old 12-25-2010, 08:31 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
Beginner's Guide to BASH Scripting:

http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
 
Old 12-25-2010, 10:28 PM   #5
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
Try this:
echo -n "Hey"; sleep 1; echo -n " man,"; sleep 1; echo -n " what's"; sleep 1; echo -n ' up?'; sleep 1
all on one line. And try this:
echo -n "H"; sleep .5; echo -n e; sleep .5; echo -n y; sleep .5; echo -n " man,"; sleep 1; echo -n " what's"; sleep 1; echo -n ' up?'
The quotes around " man," and " what's" ensure the punctuation marks aren't enterpreted as something else by bash. And the single quotes around ' up?' negates the ? so bash doesn't interpret it as a built-in variable bash uses in certain cases, like returning error codes. You'll learn neat little things like that as you go along, take the advice of the other posters and read the manual for echo and check out the bash scripting guide suggested by the other post. There are guides you can download for offline reading that you can upload to an ipad or similar document reader. That way when you're on a bus or waiting somewhere you can study it. Bash is not as powerful as a legitimate programming language but it sure is handy for saving you a lot of time on otherwise time consuming, mundane tasks like renaming multiple files, tagging your mp3 files, etc. Have fun.

Last edited by SharpyWarpy; 12-25-2010 at 11:02 PM. Reason: additional info
 
1 members found this post helpful.
Old 12-26-2010, 02:36 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
How about:
Code:
#!/bin/bash

line="What is your name?"

for word in $line
do
    echo -n "$word "
    sleep 2
done

read name

echo "Your name is $name"
 
Old 12-26-2010, 03:12 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or:
Code:
line="What is your name?"

for i in $(seq 0 ${#line})
do
  echo -n "${line:$i:1}"
  sleep 0.25
done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
the newbie help script tommytomthms5 Linux - Newbie 1 07-12-2008 10:17 PM
Help a script newbie unholy Programming 2 09-19-2004 07:05 AM
little newbie script problem uncle_fungus1 Linux - Software 4 01-20-2004 05:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration