LinuxQuestions.org
Review your favorite Linux distribution.
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, 07: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 02:10 AM.
 
Old 12-25-2010, 07: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 07:53 PM. Reason: typo.
 
Old 12-25-2010, 08:35 PM   #3
speck
Member
 
Registered: Nov 2001
Location: US
Distribution: Slackware 14.2
Posts: 341

Rep: Reputation: 83
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, 09:31 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mint, OpenBSD
Posts: 11,342
Blog Entries: 12

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

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

Rep: Reputation: 90
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-26-2010 at 12:02 AM. Reason: additional info
 
1 members found this post helpful.
Old 12-26-2010, 03:36 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,251

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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, 04:12 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:17 PM
Help a script newbie unholy Programming 2 09-19-2004 08:05 AM
little newbie script problem uncle_fungus1 Linux - Software 4 01-20-2004 06:48 PM


All times are GMT -5. The time now is 07:10 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration