,

Bitcoin price quote for Linux shell (Reddit Bitcoin)

Bitcoin

I love to work with the Linux shell (bash; Linuxmint/Ubuntu) all day, and from time to time I want to know the current price of Bitcoin and Ether. So I created a simple Linux shellscript, which displays both cross-prices to USD and EUR within the shell after typing in “btc”. I know that I could use the web for this task, but I like it this way and I also don’t want to be constantly informed (i.e. with an app on the smartphone).

Here it is, let me know if you like it.

#!/bin/bash # this simple Linux shell script uses the "jq" command line # JSON data processor pls. install "jq" first (sudo apt # install jq) then save the skript with an editor as i.e. # "btc" under a path for executables, (i.e. ~/.local/bin/) # and make it executable ("sudo chmod +x btc"). The script # uses market data from the kraken api; pls. feel free to # use any other api. The script displays the current price # of Bitcoin and Ether in USD and EUR. If you don't like # the colors, try playing around with the "tput setaf x" # (color of characters) and "tput setab x" (background # color); you might find the information frome here: # https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux # useful. Enjoy! JSN1=$(curl -s "https://api.kraken.com/0/public/Ticker?pair=XBTUSD") JSN2=$(curl -s "https://api.kraken.com/0/public/Ticker?pair=XBTEUR") JSN3=$(curl -s "https://api.kraken.com/0/public/Ticker?pair=ETHUSD") JSN4=$(curl -s "https://api.kraken.com/0/public/Ticker?pair=ETHEUR") QRAW1=$(echo $JSN1 | jq ".result.XXBTZUSD.c[0]") QRAW2=$(echo $JSN2 | jq ".result.XXBTZEUR.c[0]") QRAW3=$(echo $JSN3 | jq ".result.XETHZUSD.c[0]") QRAW4=$(echo $JSN4 | jq ".result.XETHZEUR.c[0]") RGX='"([0-9]+).[0-9]+"' Q1=$(echo $QRAW1 | sed "s/${RGX}$/1/g") Q2=$(echo $QRAW2 | sed "s/${RGX}$/1/g") Q3=$(echo $QRAW3 | sed "s/${RGX}$/1/g") Q4=$(echo $QRAW4 | sed "s/${RGX}$/1/g") RED=`tput setaf 1` GREEN=`tput setaf 2` WHITEBACK=`tput setab 7` CYANBACK=`tput setab 6` BOLD=`tput bold` RESET=`tput sgr0` echo "${WHITEBACK}${BOLD}${RED}Bitcoin: $""$Q1"" €""$Q2${RESET}"" ${BOLD}${CYANBACK}${GREEN}Ether: $""$Q3"" €""$Q4${RESET}" 

submitted by /u/fatrattombala
[link] [comments]

Leave a Reply