Today, I messed around with something pretty fun – making a little fortune-telling script using shell. It’s not going to predict your future accurately, but it’s a cool way to play with shell scripting and see what you can do with it.
Getting Started
First, I needed a place to store my “fortunes.” So, I created a simple text file. I just named it . Inside, I wrote a bunch of one-liner fortunes, you know, the kind you might find in a fortune cookie. Silly stuff, mostly.
- “You will find unexpected joy in a mundane task.”
- “A great opportunity is hiding in plain sight.”
- “Beware of squirrels bearing gifts.”
- “The stars are aligned… for someone else.”
I mean I add the fortunes manually into the file.
Building the Script
Next, I opened up my favorite text editor and started a new shell script. I usually call these things , just to be clear about what it does.
The core of the script is pretty simple. I used the shuf
command, which is awesome for randomizing lines in a file. It’s like shuffling a deck of cards. I piped (that’s the symbol) the output of shuf
to the head
command. head
just grabs the first few lines of a file, and in this case, I only wanted one line – one fortune.
So, the main part of the script looked like this:

shuf * head -n 1
I added some extra stuff around it to make it look a little nicer. For instance, I used echo
to print a little intro message before revealing the fortune. And I added some sleep time, just to make it dramatic like delay.
echo "Welcome to the Shell Divination!"
echo "Let's see what your future holds..."
sleep 2 #Dramatic Delay
shuf * head -n 1
Making it Executable
Once I was happy with the script, I saved it. Then, I needed to make it executable. This means I gave the script permission to run as a program. I did this with the chmod
command:
chmod +x *
Running the Show
Now for the fun part! I opened my terminal and typed to run the script. And there it was, my random fortune! Each time I run it, I get a different one. It is the result by using my script.
It’s a super simple project, but it’s a great way to get comfortable with basic shell commands like shuf
, head
, echo
, and chmod
. Plus, you can customize it however you want! Change the fortunes, add more messages, maybe even make it interactive. It’s all up to you.
