Register
It is currently Wed Apr 23, 2014 12:46 am

Select Case Help


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Jun 13, 2009 7:28 pm   

Joined: Sat Jun 13, 2009 7:25 pm
Posts: 2
Hello all.

I'm a college student and am very new to BASH scripting. I'm trying to write a simple script for a homework assignment and I keep getting the following problem:

Your Tax Information is as follows
GPEx: line 15: syntax error near unexpected token `('
GPEx: line 15: ` *(<= 10000))'



This is all the script for the file.


echo "Welcome to my week 7 custom project script."
echo "This script will calculate taxes."

echo "Please enter your name"
read Name
echo "Thank You"
echo " "
echo "Please enter your income for the given time period"
read Income
echo "Alright, Thank You" $Name
echo " "
echo "Your Tax Information is as follows"

case $Income in
*(<= 10000))
(("$IncomePostTax" = "$Income * .10"))
echo "Because you made $10,000 or less during that time period your only getting charged 10%"
;;
*((>=10001 && <= 20000)
(("$IncomePostTax" = "&Income * .15"))
echo "Because you made between $10,000 and $20,000 in the given time period your only getting charged 15%"
;;
*)
echo "Invald data, please re-enter the data"
;;
esac

Can somebody please tell me what I did wrong.
Thanks in advance.


Top
 Profile  
 PostPosted: Mon Jun 15, 2009 7:31 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
You're using case where you'd better use if...elif...elif...fi
As far as I know, case can't evaluate .
for -le -ge, see help test.
Bash can't evaluate decimal arithmetic expression.
You need to protect the dollar sign as it doesn't call a variable.
So
Code:
if [ $Income -le 10000 ]; then
   IncomePostTax=$(echo "scale=2; $Income * .10" | bc)
   echo "Because you made $10,000 or less during that time period your only getting charged 10%"
elif [ $Income -ge 10001 ] && [ $Income -le 20000 ]; then
   IncomePostTax=$(echo "scale=2; $Income * .15" | bc)
   echo "Because you made between \$10,000 and \$20,000 in the given time period your only getting charged 15%"
else
   echo "Invald data, please re-enter the data"
fi


Top
 Profile  
 PostPosted: Mon Jun 15, 2009 9:34 am   

Joined: Sat Jun 13, 2009 7:25 pm
Posts: 2
Thank You! After taking that and entering it the script ran successfully. I was also able to look up what you said in my book and learn from it. I appreciate your time and thank you again.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 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:  


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