Skip to main content
Version: 2024

Discover D&D Species with Shell Scripting

✅ Learning Objectives

  1. Learn to use cURL
  2. Learn to write a simple Bash script
  3. Learn to make a script interactive

Preparing Your Bash Adventure​

Before we set off on our coding journey, make sure you have these:

  1. A command-line terminal (Bash)
  2. An internet connection
  3. Your excitement and curiosity

Building the D&D Species Search Tool​

  1. 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 curl command. 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!

  2. Create Your Own Spell (Bash Script):

    Now, let's create a magical script named dnd_species_search.sh using your favorite text editor (like nano, vim, or even a code editor).

    #!/bin/bash

    echo "Welcome to the D&D Species Search Tool!"
    echo "-----------------------------------"
    echo

    read -p "Enter the name of a D&D species: " species_name

    curl -L "https://www.dnd5eapi.co/api/2024/species/$species_name" -H 'Accept: application/json'
  3. 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
  4. Embark on Your Quest:

    Cast your spell and run your script:

    ./dnd_species_search.sh

    You'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! 🎉🏰🧝‍♂️