This bash script fetches random inspirational quotes from two different online APIs and displays them in the terminal. It also saves these quotes to a text file for future reference.
To run this script, follow these steps:
-
Ensure you have
curl
andjq
installed on your system. If not, you can install them using the following commands:sudo apt-get update sudo apt-get install curl jq
-
Make the script executable:
chmod +x script_name.sh
-
Run the script:
./script_name.sh
Replace script_name.sh
with the actual name of the script.
-
The script first specifies the category of the quote as "inspire".
-
It then fetches a random quote from the Quotable API.
-
The script checks if the API request was successful. If not, it displays an error message and exits.
-
If the API request was successful, the script checks if the API returned an error. If so, it displays the error message and exits.
-
If there were no errors, the script extracts the content and author from the JSON response and displays the quote.
-
The quote is then saved to a file named
quotes.txt
. -
The script repeats the above steps for the They Said So API to fetch the quote of the day.
The script includes error handling for unsuccessful API requests and for errors returned by the API. If an error occurs, the script will display an error message and exit.
This script requires curl
to make the API requests and jq
to parse the JSON responses.