-
Notifications
You must be signed in to change notification settings - Fork 0
Shell Example Code
MMDRZA edited this page Oct 18, 2024
·
1 revision
#!/bin/bash
# URL of the JSON data
raw="https://raw.githubusercontent.com/Crypto-Static/Rate/main/rateStatic.json"
# Fetch JSON data using curl
response=$(curl -s "$raw")
# Check if the request was successful
if [ $? -eq 0 ]; then
# Parse JSON and extract the required fields using jq
echo "$response" | jq -r '.[] | "\nSymbol: \(.symbol)\nLAST: \(.lastPrice)\nHIGH: \(.highPrice24h)\nLOW: \(.lowPrice24h)\nCHANGE: \(.changeRate)\nUPDATED: \(.lastUpdated)"'
else
echo "Failed to fetch data. HTTP status: $?"
fi
- curl: Used to make the HTTP request and fetch the JSON data.
- jq: A lightweight command-line JSON processor that allows parsing and extracting specific fields from the JSON data.
-
if [ $? -eq 0 ]; then
: This checks whether thecurl
command was successful (exit status 0). - jq -r: This flag is used to output the extracted fields as raw text, avoiding double quotes around strings.
- Install
jq
if it's not already installed:
sudo apt-get install jq # Ubuntu/Debian
brew install jq # macOS (Homebrew)
chmod +x crypto_fetch.sh
./crypto_fetch.sh
👨💻 Programmer : PyMmdrza 🌍 Official Website Mmdrza.Com 📧 Email : Pymmdrza@gmail.com
📧 first@programmer.net