Advertisement
metalx1000

Get Bitcoin Value with BASH script

Jan 9th, 2025
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.28 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2025  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation version 3 of the License.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18. # api will block you if you do too many requests
  19. # limit how often you run this.
  20. # also see https://pastebin.com/fLjwBz4x
  21.  
  22. url="https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
  23. value="$(wget -qO- "$url")"
  24.  
  25. # Create Array by spitting String at :
  26. IFS=":" read -ra array <<<"$value"
  27.  
  28. # create Array from 3 field of previous array
  29. # Now splitting at }
  30. IFS="}" read -ra array2 <<<"${array[2]}"
  31.  
  32. #output with Dollar Sign and Comma
  33. printf "$%'d\n" "${array2[0]}"
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement