Quote:
Thanks i'll have a read |
Quote:
You have to read the documents that were given. Don't expect to learn bash in 10mn. Try one of the example and add your little bit, modify the code, see what it gives. It was my way of understanding computer languages. You should practice, not only read. Meanwhile, try this: Code:
bc Code:
100-2 Code:
98 Code:
98/0.93 Code:
105 Code:
scale=2 Code:
98/0.93 Code:
105.37 if you want to quit bc, type on a newline Code:
quit Now you have to understand the concept of pipes (read the manuals again). Code:
command1|command2 In other words, it's like if you were doing command1 which gives result X and then you run command2 and you copy paste X. For this, command2 has to be a command that is asking for something, like bc, not like ls (when you type ls, your shell doesn't ask you anything) Now you want to use bc without typing anything. Retype what was above and put a ; between each command Code:
echo "scale=2;98/0.93" | bc -l and your shell displays the result: Code:
105.37 Code:
A=100; B=2; C="0.93"; D=`echo "scale=2;($A-$B)/$C" | bc -l` |
I've now identified that i need to use bc instead of let, to get the total. But the script still doesnt work.
echo please enter the amount in `$` that you wish to convert | bc[/COLOR]ou entered converts to $total |
ok you have an opening ` but no closing one. i assume you don't know what `'s do? they run the contents of the quotes, so in your case you would want to exectue the echo to make the mathematical expression, pipe it to bc and capture the output, so the entire thing shoudl be in `'s (backticks) actually, backticks are old now, and you shoudl be using $( command ) style instead, which i think is a lot clearer for learning anyway.
|
total=`echo "scale=2; $amount * $rate" | bc`
# Or use scale=3 to produce the whole amount cause you need to round off. |
i corrected this, but it still wont work.
surely something like this could be written in under 10 lines of code |
You also need thins called scholar values which are designated by the use of the dollar sign in perl.
examples of scholar values are as follows: $total $intrest |
Quote:
|
Quote:
|
Quote:
Sorry the errors are as follows: line 1: $: command not found (standard in parse error) Thats it. It doesnt actually output any numbers at all. From my reading i've gathered that i may need to assign the "Euro & pounds" as some sort of variable. I may be wrong. But i dont seem to have made progress, i cant even get a number to appear as the result, yet alone the correct conversion. |
Did u add
read rate right after echo What is the exchange rate? |
Quote:
I could point to "A Guide to Unix Shell Quoting" but in short: using backticks in line one without using single quotes encapsulating the echoed string is the problem, since it will have the shell interprete the `$` part as a command. Sorter: do not use backticks unless you know you should. Before you continue with the next problem I suggest you cooperate by rereading this thread and the docs mentioned. |
I've worked out how to do it now. Thanks for everyones help. You may now close this thread.
|
can i suggest for your future questions, provide error messages, provide code, provide the answer, not just say it's working. that way other people in your situation can get as much from the thread as you did in the first palce.
|
Amen to that bro
|
All times are GMT -5. The time now is 11:25 AM. |