Register
It is currently Fri Nov 28, 2014 1:17 pm

my first useful script - book


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Aug 07, 2007 5:39 pm   

Joined: Tue Aug 07, 2007 5:02 pm
Posts: 1
Location: United States
I made a script called "book" and it is the first useful bash script I have made.
This script asks you how many pages your book has, how much you've read,
and how many days you have to complete it.
It will then tell you how many pages to read a day and places a schedule in a file called book.txt.

Code:
# /bin/bash
# book bash script 0.1
# by ned

echo  "Please answer the questions correctly!"
echo  "I haven't put any error checking in yet!"
read -p "How many pages does the book contain? " contain
read -p "How many pages have you finished reading? " donerd
read -p "How many days (including today) do you have to read it? " days

perday=$((($contain-$donerd)/$days))
echo "You need to read $perday pages each day."
echo "The pages per day and schedule have been placed in book.txt."

{
echo "You need to read $perday pages each day."
for ((a=1; a < days ; a++))
do
   onday=$((donerd += perday))
   echo "On day $a, read to page $onday."
done
echo "On day $days, finish the book!"
} > book.txt

exit 0

If anyone has tips for improvement, such as better code or a new feature please post!
One of the most important things I'd like to add is error checking.


Top
 Profile  
 PostPosted: Wed Aug 08, 2007 9:02 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
best way to work on error checking is to run the script over and over... and break it in anyway possible. like putting letters where you are expecting numbers, especially for numeric calculations, thats a really fun one.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP