Fedora Linux Support Community & Resources Center
  #1  
Old 27th April 2007, 11:11 PM
KoubaK Offline
Registered User
 
Join Date: Oct 2006
Location: The Bronx, New York
Age: 25
Posts: 15
Scripting Help!

hey, guys im new to UNIX and i need help.. I need to write a script which will tell you if you entered an even (e.g., 2, 4, 6...) or odd number (e.g., 1, 3, 5...) and then give you the summation of the number you entered. For example, if you entered 5 it will give 15 (1+2+3+4+5). I'm suppose to use if and loops .. I got no idea on how to do so.. below is what I got sooo far!

Code:
#!/bin/bash

echo " This script will tell you if you entered an even (e.g., 2, 4, 6...) or odd number (e.g., 1, 3, 5...) and then give you the summation of the number you entered. For example, if you entered 5 it will give 15 (1+2+3+4+5)"

echo "Please, enter your name and PRESS ENTER"
read name

echo 'Please, enter an integer number (e.g., 1, 2, 3...) and PRESS ENTER:'
fi
and I am to follow this example!

Code:
This script will tell you if you entered an even (e.g., 2, 4, 6...) or odd number (e.g., 1, 3, 5...) and then give you the summation of the number you entered. For example, if you entered 5 it will give 15 (1+2+3+4+5)

Please, enter your name and PRESS ENTER
name

Please, enter an integer number (e.g., 1, 2, 3...) and PRESS ENTER: 6
         name you have entered 6 please see the results

         The number you entered 6 is an even number
         The summation of 6 is 21
anyone? please help!! lol
__________________
Quote:
Can't remember where I left my Fedora Stick!
Reply With Quote
  #2  
Old 28th April 2007, 03:29 AM
lmo Offline
Registered User
 
Join Date: Mar 2007
Posts: 1,047
Code:
#!/bin/bash
read -p "Please enter your name: " name
read -p "$name Please, enter an integer number (e.g., 1, 2, 3...) and PRESS ENTER: " number
digs=$number
sum=0
while [ $digs -gt 0 ];do sum=$(( sum + $digs )); digs=$(( $digs -1 )); done
echo "The summation of $number is $sum and I forgot about even numbers"
if [ $(( $number % 2 )) -eq 0 ];then
  echo "$number is an even number"
else
  echo "$number is not an even number"
fi
echo " see: 'man bash'  and 'man test' for an enormous amout of information."

Last edited by lmo; 28th April 2007 at 03:56 AM.
Reply With Quote
  #3  
Old 28th April 2007, 05:45 AM
KoubaK Offline
Registered User
 
Join Date: Oct 2006
Location: The Bronx, New York
Age: 25
Posts: 15
thanks man!!! and thanks for the extra comment!! :P guess I will have too!!
__________________
Quote:
Can't remember where I left my Fedora Stick!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting help boknoy Using Fedora 3 3rd August 2007 02:44 PM
help with scripting mitchell2345 Using Fedora 2 28th February 2007 01:08 AM
Scripting help mitchell2345 Using Fedora 5 23rd January 2007 07:06 AM
cron scripting/bash scripting coolbeansdude51 Using Fedora 7 16th January 2007 03:13 AM
Scripting... CICA Using Fedora 12 30th January 2006 10:03 PM


Current GMT-time: 15:59 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat