A friendly assistant script written in Bash that interacts with the user to perform various tasks like telling jokes, fetching the time, performing calculations, providing weather updates, and even speaking text aloud.
-
Tell a Joke:
- Randomly selects a joke from a
jokes.txtfile. - If the
jokes.txtfile is missing, it notifies the user.
- Randomly selects a joke from a
-
Display the Current Time:
- Fetches and displays the current date and time using the
datecommand.
- Fetches and displays the current date and time using the
-
Perform Calculations:
- Accepts a simple mathematical expression from the user (e.g.,
4 + 5) and calculates the result.
- Accepts a simple mathematical expression from the user (e.g.,
-
Get Weather Updates:
- Fetches the latest weather information from
wttr.in.
- Fetches the latest weather information from
-
Text-to-Speech (Optional):
- Converts text into speech using the
espeakcommand (requiresespeakto be installed).
- Converts text into speech using the
-
Interactive Mode:
- Prompts the user for input and handles commands like
time,joke,calculate,weather,speak, orexit.
- Prompts the user for input and handles commands like
-
Non-Interactive Mode:
- Allows predefined queries as command-line arguments (e.g.,
./friend.sh time).
- Allows predefined queries as command-line arguments (e.g.,
- Bash Shell: Ensure Bash is installed on your system.
curlCommand: Required for fetching weather data.espeakCommand (Optional): Required for thespeakfeature.
git clone <repository-url>
cd friend-assistantchmod +x friend.shCreate a file named jokes.txt in the same directory, with each joke on a new line:
Why did the scarecrow win an award? Because he was outstanding in his field!
Why don't programmers like nature? It has too many bugs.
Why do cows have hooves instead of feet? Because they lactose.
Run the script without arguments to start the interactive interface:
./friend.shRun the script with a predefined query:
./friend.sh time # Display the current time
./friend.sh joke # Tell a random joke
./friend.sh calculate # Perform a calculation
./friend.sh weather # Get the weather forecast
./friend.sh speak # Speak text aloudHello! I am your friendly assistant. How can I help you today?
What would you like to know? (time, joke, calculate, weather, speak, exit)
> joke
Here's a joke: Why don't programmers like nature? It has too many bugs.
> time
The current time is: Mon Jan 25 15:00:00 UTC 2025
> weather
Fetching weather information...
[Weather data appears here]
> exit
Goodbye!
-
Add More Jokes:
- Edit the
jokes.txtfile to include more jokes.
- Edit the
-
Change Weather Source:
- Replace
curl -s wttr.inin thetell_weatherfunction with a different weather API.
- Replace