Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-11-2004, 03:21 PM   #1
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

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.

Old 02-11-2004, 04:00 PM   #2
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...

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

Rep: Reputation: 36
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

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"
     if [ p -eq 1 ]; then
          echo "No"
     if [ p -eq 2 ]; then
          echo "No way!"
     z=`expr $z + 1`


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 04:19 AM
New to C++ help with simple script Fredstar Programming 9 08-08-2005 11:09 AM
A Simple Script fiod Linux - General 3 09-20-2003 08:56 PM
Simple Script fiod Linux - General 2 09-08-2003 03:03 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:16 PM.

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