Discover D&D Species with Shell Scripting
✅ Learning Objectives
- Learn to use cURL
- Learn to write a simple Bash script
- Learn to make a script interactive
Preparing Your Bash Adventure
Before we set off on our coding journey, make sure you have these:
- A command-line terminal (Bash)
- An internet connection
- Your excitement and curiosity
Building the D&D Species Search Tool
-
Summon the Magic of Curl:
Open your command-line terminal and let's cast our first spell to fetch D&D species information using the mighty
curlcommand. Type or copy-paste the following:curl -L 'https://www.dnd5eapi.co/api/2024/species/dwarf' -H 'Accept: application/json'When you hit Enter, you'll unveil the details of the D&D Dwarf species!
-
Create Your Own Spell (Bash Script):
Now, let's create a magical script named
dnd_species_search.shusing your favorite text editor (likenano,vim, or even a code editor).#!/bin/bashecho "Welcome to the D&D Species Search Tool!"echo "-----------------------------------"echoread -p "Enter the name of a D&D species: " species_namecurl -L "https://www.dnd5eapi.co/api/2024/species/$species_name" -H 'Accept: application/json' -
Enchant Your Script:
Before you can use your script, you'll need to make it executable (aka runnable). In your terminal, type:
chmod +x dnd_species_search.sh -
Embark on Your Quest:
Cast your spell and run your script:
./dnd_species_search.shYou'll be prompted to enter the name of a D&D species. For now, let's try "dwarf" and see what magnificent details unfold!
The Mystical Output Awaits!
Prepare yourself, for the secrets of the D&D Dwarf species shall be revealed before your very eyes! Once you enter "dwarf," you should expect an awe-inspiring response similar to this:
Welcome to the D&D Species Search Tool!
-----------------------------------
Enter the name of a D&D species: dwarf
{
"index": "dwarf",
"name": "Dwarf",
"url": "/api/2024/species/dwarf",
"type": "Humanoid",
"size": "Medium",
"speed": 30,
"traits": [
{
"index": "darkvision-120",
"url": "/api/2024/traits/darkvision-120",
"name": "Darkvision (120 ft.)"
},
...
],
"updated_at": "2026-09-20T07:44:55.417Z",
"subspecies": []
}
Celebrate Your Coding Victory!
Congratulations, young adventurers! You've crafted your very own D&D Species Search Tool using Bash scripting. You can now explore different species and learn about their unique abilities, traits, and more. Your journey has just begun, and there's so much more to discover in the realm of coding and Dungeons & Dragons. May your code be bug-free and your rolls be critical hits! 🎉🏰🧝♂️