Register
It is currently Sat Dec 20, 2014 3:47 pm

Help!!!! Please :)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Apr 09, 2012 2:23 pm   

Joined: Mon Apr 09, 2012 2:20 pm
Posts: 2
Could someone please help with this script?
Thanks!

Code:
total=0
echo "What is the length of the floor of the room (in ft)"
read length
echo "what is the width of the floor of the room (in ft)"
read width
let "sqroom= $length * $width"
echo "Please choose a carpet: all purpose - 2 dollars per sq.ft., plush - 3 dollars per sq. ft., shag - 4 dollars per sq.ft."
read carpet
echo "Is an installation required? (75 dollar fee) Yes or No"
read install
echo "How many rooms require carpet?"
read rooms
if [ "$carpet" = "all purpose" && "install" = "yes" ]

   then
      let "total = $sqroom * $rooms * 2  + 75"

      elif [ "$carpet" = "all purpose" && "$install" = "no" ]
      
      then

      let "total = $sqroom * $rooms * 2"

elif [ "$carpet" = "plush" && "$install" = "yes" ]

      then

      let "total = $sqroom * $rooms * 3  + 75"

      elif [ "$carpet" = "plush" && "$install" = "no" ]
      
      then

      let "total = $sqroom * $rooms * 3"
elif [ "$carpet" = "shag" && "$install" = "yes" ]

      then

      let "total = $sqroom * $rooms * 3  + 75"

      elif [ "$carpet" = "shag" && "$install" = "no" ]
      
      then +:)

      let "total = $sqroom * $rooms * 3"
fi
echo "your total is $total"


Top
 Profile  
 PostPosted: Mon Apr 09, 2012 2:57 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Hello Confused Student, and welcome to the forum!

What exactly are you having trouble with in this script?

I see a pretty obvious syntax error:
Code:
    then +:)


Is the "+:)" there for a reason?

Also, if you want your if statements to match two conditions, each condition should be enclosed in its own set of brackets (and you only need on ampersand. two ampersands is like saying "then")

For instance!
Code:
# THIS
if [ "$carpet" = "all purpose" && "install" = "yes" ]

# Should be something like this:
if [ "$carpet" = "all purpose" ] & [ "install" = "yes" ]


I hope this helps!


Top
 Profile YIM  
 PostPosted: Mon Apr 09, 2012 3:30 pm   

Joined: Mon Apr 09, 2012 2:20 pm
Posts: 2
This helped a lot, thanks its hard for me to debug bash scripting still trying to get the hang of it.


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 1 guest


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