Short how-to: BASH script to manually check current Bitcoin price

I’m not much intro cryptocurrencies but I got this nice script that outputs the price of Bitcoin when invoked:

$ cat /usr/bin/bitcoin

curl -s | python -c "import json, sys; print(json.load(sys.stdin)['bpi']['USD']['rate'])"

It’s simple and effective. Maybe someone finds a use for this.
It practically reads an online JSON database file via the Coindesk API using curl and then uses Python to read certan tables from that JSON file.


1 Like

Another alternative could be to use jq command to parse the JSON format instead of parsing JSON with python.

For example:

$ curl -s  | jq '.bpi.USD.rate'
$ curl -s  | jq '.bpi.GBP.rate'
$ curl -s  | jq '.bpi.EUR.rate'

1 Like

That’s very cool. Didn’t know about jq.