From a8f1442b436398bacae22d8ea6b5f0965cf797a7 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Mon, 11 Oct 2021 20:03:37 +0200 Subject: [PATCH] Handle BTC value not available --- home/.local/bin/scripts/bitcoin | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/home/.local/bin/scripts/bitcoin b/home/.local/bin/scripts/bitcoin index d1ea4ef..78316b5 100755 --- a/home/.local/bin/scripts/bitcoin +++ b/home/.local/bin/scripts/bitcoin @@ -1,7 +1,12 @@ #!/bin/sh -BTC_DATA=$(curl https://api.coindesk.com/v1/bpi/currentprice.json 2>/dev/null) -BTC_PRICE=$(echo $BTC_DATA | jq -r ".bpi.USD.rate_float") -BTC_PRICE=$(printf "%.2f" "$BTC_PRICE") +BTC_DATA=$(curl https://api.coindesk.com/v1/bpi/currentprice.json 2>/dev/null | echo 'ERR') + +if [ "$BTC_DATA" != "ERR" ]; then + BTC_PRICE=$(echo $BTC_DATA | jq -r ".bpi.USD.rate_float") + BTC_PRICE=$(printf "%.2f" "$BTC_PRICE") + echo \$"$BTC_PRICE" +else + echo "N/A" +fi -echo \$"$BTC_PRICE"