Member-only story

Personalized Fortune Cookie Generator using Shell Scripting

Rakan Khaled
3 min readAug 28, 2024
Photo by Meritt Thomas on Unsplash

To create a personalized fortune cookie generator shell script, we’ll write a simple script that randomly selects and displays a fortune (or quote) from a predefined list. The script will use basic shell scripting tools and commands to achieve this.

LETS GOOOOOOOOOO!

Step 1: Set Up Your Environment

  1. Open a Terminal: You’ll write the script in your terminal or a text editor.
  2. Create a New Script File: Use your preferred text editor to create a new shell script file.
touch fortune_cookie.sh
chmod +x fortune_cookie.sh # Make the script executable

Step 2: Write the Script

Edit fortune_cookie.sh with your text editor (e.g., nano, vim, code, etc.). Here is the script:

#!/bin/bash

# Define an array of fortune cookies or quotes
fortunes=(
"You will have a great day today!"
"An unexpected event will bring you joy."
"You will meet someone special very soon."
"Adventure is on the horizon."
"Your hard work will soon pay off."
"Happiness is a journey, not a destination."
"Believe in yourself and all that you are."
"Good news will come to you by mail."
"You will conquer your challenges."
"New…

--

--

Rakan Khaled
Rakan Khaled

No responses yet