-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
  • 741,623
  • 53
  • 500
  • 612
dibusure
  • 31
  • 1
  • 3
  • 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
  • 5
    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

2 Answers2

1

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
  • 105,803
  • 17
  • 152
  • 177
1

As noted above in comments:

You should check what cURL is returning because the data you're trying to parse with jq isn't JSON. It's more likely an HTML error message that jq doesn't know how to parse.

LinuxDisciple
  • 2,289
  • 16
  • 19