LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-11-2004, 04:21 PM   #1
granny
Member
 
Registered: Nov 2002
Distribution: RH
Posts: 141

Rep: Reputation: 15
Help on simple script


hey guys, I am new to scripting. I would like to write a simple script that would kinda be a magic 8 ball. maybe start with

#!/bin/bash
echo "what is your question?"


I am stuck after this. I don't mind typing in several things, but I would like to randomize the answers like yes, no , definitely, in your dreams. Any help is appreciated.

TIA
 
Old 02-11-2004, 05:00 PM   #2
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
Take some inspiration from this...

http://www.tldp.org/LDP/abs/html/ran...tml#RANDOMTEST

Shouldn't be too hard to make it do what you want.
 
Old 02-11-2004, 05:02 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
This gives you ten random answers picked from a choice of three possible answers. You make the code shorter using case.

You can use /dev/random as a source for random numbers instead of the environment variable RANDOM
Code:
#!/bin/ksh
     

let z=0
while [ z -lt 10 ] ; do
     let p=0
     p=`echo $RANDOM`
     p=`expr $p % 3`

     
     if [ p -eq 0 ]; then
          echo "Yes"
     fi
     if [ p -eq 1 ]; then
          echo "No"
     fi
     if [ p -eq 2 ]; then
          echo "No way!"
     fi
     z=`expr $z + 1`
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
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 05:19 AM
New to C++ help with simple script Fredstar Programming 9 08-08-2005 12:09 PM
A Simple Script fiod Linux - General 3 09-20-2003 09:56 PM
Simple Script fiod Linux - General 2 09-08-2003 04:03 PM
Simple C Shell script is not so simple elconde Programming 2 09-17-2001 12:53 AM


All times are GMT -5. The time now is 09:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration