command to convert currency in Ubuntu server using gcalccmd

Solution 1:

You can download qalculate from the Ubuntu Software Centre. This application allows you to download current rates and calculate the exchange rate from the command line.

$ sudo apt install qalc
$ qalc
> 1 GBP to euro
It has been 750 day(s) since the exchange rates last were updated.
Do you wish to update the exchange rates now? yes

  1 * GBP = approx. EUR 1.1756407

> 1 GBP to USD

  1 * GBP = approx. $1.3931343

> 

You can then update the rate using the command exrates on the command lie in terminal. Use help from the command line when you are in the tool to see the various commands available.

$ qalc
> help

Enter a mathematical expression or a command and press enter.
Complete functions, units and variables with the tabulator key.

Available commands are:

approximate
assume ASSUMPTIONS
base BASE
delete NAME
exact
exrates
factor
find/list [NAME]
function NAME EXPRESSION
info
mode
partial fraction
save/store NAME [CATEGORY] [TITLE]
save definitions
save mode
set OPTION VALUE
expand
to/convert UNIT or "TO" COMMAND
variable NAME EXPRESSION
quit/exit

Commands for RPN mode:
rpn STATE
stack
clear stack
copy [INDEX]

move INDEX 1 INDEX 2
pop [INDEX]
rotate [DIRECTION]
swap [INDEX 1] [INDEX 2]

Type help COMMAND for more information (example: help save).
Type info NAME for information about a function, variable or unit (example: info sin).
When a line begins with '/', the following text is always interpreted as a command.

For more information about mathematical expression, different options, and a complete list of functions, variables and units, see the
relevant sections in the manual of the graphical user interface (available at http://qalculate.github.io/manual/index.html).

You would need to have qalc installed (but not running) and you can then call the exchange rate from the command line or a script by using (for example):

1 GBP to EUR

You can also use qalc -t 1 GBP to EUR (-t = terse, the opposite of verbose) but you can also use the awk command to split out the value only as in:

awk -F' ' '{print $2}' <<< `qalc -t 500 GBP to EUR`

This will give the value 560.63584 (at the rate given)