Web services in the console (bash)

I spend a lot of my day in a terminal window, and I love automating stuff with bash scripts. Sometimes those scripts need to do perform actions based on external conditions: location (country), weather, bandwidth speed …

Here are a couple of terminal-ready web services that can give you external information. You can interrogate them from the command-line (CLI). For this you will need a CLI web client like curl, wget or http; at least one of those should already be installed on your MacOS/Linux/Win10 WSL terminal.

IP address/location

There is the website ifconfig.co, run by Martin Polden (Norway), based on his mpolden/echoip project (written in Go). It will give you your IP4/IP6 network address, and based on that, also your approximate geographical location.

Alternatives: ip-api.com, ifconfig.io, ipinfo.io


Igor Chubin has developed a neat ASCII weather forecast service wttr.in that works great in CLI mode. It runs on Python and the code is on chubin/wttr.in.

Developer help

Igor also developed cheat.sh (github: chubin/cheat.sh) which allows a fast way to answer “how does XYZ work again?”

Create QR code

Another genius project of Igor Chubin: qrenco.de (github)

Bandwidth speed

Well this is a bit different, because you can’t measure internet speed with just a call to an external service.

There is sindresorhus/fast-cli which uses the Fast.com (Netflix) servers, but it’s a huge npm library (with puppeteer, i.e. a full headless browser under the hood) you have to install on your local computer,

A bit lighter is sivel/speedtest-cli, which is a Python script that uses the servers from Speedtest. It is lighter in that it fetches the last version of the code from Github (with curl) and feeds this right into a python interpreter. Obviously you need Python on your machine.

$ curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
Retrieving speedtest.net configuration...
Testing from Telenet (
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Proximus (Schaarbeek) [7.34 km]: 19.867 ms
Testing download speed...
Download: 128.29 Mbit/s
Testing upload speed...
Upload: 18.26 Mbit/

Dictionary lookup

$ curl dict://dict.org/d:albeit
150 1 definitions retrieved
151 "Albeit" gcide "The Collaborative International Dictionary of English v.0.48"
Albeit \Al`be"it\, conj. [OE. al be although it be, where al is
   our all. Cf. {Although}.]
   Even though; although; notwithstanding. --Chaucer.
   [1913 Webster]

         Albeit so masked, Madam, I love the truth. --Tennyson.
   [1913 Webster]

Create short URL

$ curl -F shorten=https://blog.forret.com https://ttm.sh 

Publish a file (image)

 $ curl -F'file=@test.jpg' https://0x0.st
$ curl --upload-file ./results.txt https://transfer.sh/results.txt https://transfer.sh/66nb8/results.txt

Exchange rates

Another CLI service by Igor chubin : rate.sx for cryptocurrency exchange rates.

I had to search a bit but I also found an API for ‘regular’ currency exchange rates: exchangeratesapi.io (via alexanderepstein/Bash-Snippets)

Symbolic maths

The Newton web service (Github) by Gerald Nash allows you to do things like:

$ curl https://newton.now.sh/derive/x\^3+2x\^2
{"operation":"derive","expression":"x^3+2x^2","result":"3 x^2 + 4 x"}

$ curl https://newton.now.sh/factor/3x\^3+x\^2 
{"operation":"factor","expression":"3x^3+x^2","result":"x^2 (3 x + 1)"}

$ curl https://newton.now.sh/zeroes/x\^3\-2x\^2

Music APIs

$ curl https://api.lyrics.ovh/v1/prince/purple-rain
{"lyrics":"I never meant to cause you any sorrow\r\n(...)purple rain"}

$ curl "https://tastedive.com/api/similar?q=steely+dan"
{"Similar": {"Info": [{"Name": "Steely Dan", "Type": "music"}], "Results": [{"Name": "Donald Fagen", "Type": "music"}, (...){"Name": "Looking Glass", "Type": "music"}]}}

Using web services in a bash script

If you want to use these web tools in a script, you can easily put their output into a bash variable:

city=$(curl -s ifconfig.co/city)      # -s = silent
city=$(wget -q -O- ifconfig.co/city). # -q = quiet, -O- = to stdout
city=$(http --ignore-stdin ifconfig.co/city) # don't read from stdin

If the web service returns JSON instead of plain text, you will need jq to filter the data you want:

$ curl -s "https://newton.now.sh/derive/x^3+2x^2" | jq -r '.result'
3 x^2 + 4 x

$ curl -s "https://api.exchangeratesapi.io/latest?base=EUR" | jq '.rates.USD'

More console web services can be found on https://github.com/chubin/awesome-console-services

💬 webdev 🏷 bash 🏷 cli 🏷 command 🏷 curl 🏷 macos 🏷 service 🏷 terminal 🏷 web