Register
It is currently Sun Nov 23, 2014 11:09 pm

Problems with expr


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Sep 10, 2013 8:23 am   

Joined: Tue Sep 10, 2013 8:15 am
Posts: 2
Hey guys B-)
I have a problem with a little program i did wrote.
I want that program to calculate how much the euro is in dollar or the dollar in euro.

#! /bin/bash
clear
title="Hallo, ich werde ihnen helfen, ihr Geld umzurechnen!"
prompt="Wählen sie aus, wie sie umrechnen wollen! "
options=("Von Euro in Dollar" "Von Dollar in Euro")

echo "$title"
PS3="$prompt"
select opt in "${options[@]}" "Quit"; do

case "$REPLY" in
1) echo -n "Wie viel Euro haben sie?: "
read euro
erg=expr $euro*1,3126

echo "$euro Euro sind umgerechnet $erg $."

;;

2) echo -n "Wie viel Dollar haben sie?: "
read dollar
erg= expr $dollar / 1.3126
echo "$dollar Dollar sind umgerechnet $erg €."

;;



esac

done


My problem is in red color. How do I write the expr command? How I wrote it is wrong..

sorry for my bad english guys :-B

Thanks for answers :)


Top
 Profile  
 PostPosted: Wed Sep 11, 2013 2:49 am   

Joined: Tue Sep 10, 2013 8:15 am
Posts: 2
pls help :-/


Top
 Profile  
 PostPosted: Wed Sep 11, 2013 7:20 pm   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
a working example may help. It calculates distance / speed = hours of travel
Code:
#!/bin/bash
# traveltime - a program to calculate how long it will
# take to travel a fixed distance
# syntax: traveltime miles mph

X60=$(($1 * 60))
TOTMINUTES=$(($X60 / $2))
HOURS=$(($TOTMINUTES / 60))
MINUTES=$(($TOTMINUTES % 60))
echo "The trip will take $HOURS hours and $MINUTES minutes"


Code:
travel 60 120
60 miles @ 120 MPH
The trip will take 0 hours and 30 minutes

Good Luck.
http://mywiki.wooledge.org/ArithmeticExpression
http://tldp.org/LDP/abs/html/arithexp.html


Top
 Profile WWW  
 PostPosted: Wed Sep 11, 2013 10:52 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 567
hi,

``expr'' is not a bash internal command, and can't calculate floats.
use ``bc''.
see:
Code:
man bc


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 7 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