Attempting to write my first shell script to get the bitcoin price only when I'm not idle. After adding the if statement I receive:
/home/a/.scripts/bitcoin: line 3: [: -ge: unary operator expected
Code:
#! /usr/bin/bash
if [ $xprintidle -ge 600000 ]; then
URL="https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=GBP"
response=$(curl -s -w "%{http_code}" $URL)
http_code=$(tail -n1 <<< "$response") # get the last line
content=$(sed '$ d' <<< "$response") # get all but the last line which contains the status code
echo "$response" | sed -e 's/{"GBP":\(.*\)}200/\1/'
else
echo "Idle"
fi