-2

I have this script and this startup error ( parse error: Invalid numeric literal at line 1, column 10 ) , what should I do? P.S. The file is written in bash.

#!/bin/sh

DATA=$(curl -s 'https://api.coinmarketcap.com/v2/ticker/' | jq -r '.data ."1" .quotes .USD .price')
echo $DATA
#printf "%0.0f\n" $DATA
Barmar
  • 669,327
  • 51
  • 454
  • 560
dibusure
  • 1
  • 1
  • 1
  • That error is coming from `jq`, not `bash`. – Barmar Jun 08 '21 at 15:31
  • 2
    If the shebang says `#!/bin/sh` this is not a Bash script. See [Difference between sh and bash](https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash) – tripleee Jun 08 '21 at 15:33
  • 4
    That API is no longer operating. It returns a page that displays an error message, not the JSON you're expecting. – Barmar Jun 08 '21 at 15:33

1 Answers1

0

With a valid API KEY, the following curl invocation:

curl -H "X-CMC_PRO_API_KEY:$KEY" -H "Accept: application/json" \
-d "start=1&limit=5000&convert=USD" \
-G https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest 

yields valid JSON, for which the jq query:

 jq '.data[0].quote.USD.price' 

yields

32884.18011827609

Notes:

  • arrays are indexed by integers, not strings;
  • jq's "index origin" for arrays is 0;
  • there is no need for the -r option in this case.
peak
  • 88,177
  • 15
  • 123
  • 150