this BASH script will KILL you.
Based on NetworkChuck's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Start with an executable Bash script and a shebang, then build interactivity by prompting for input and storing it in variables with `read`.
Briefing
A Bash script can be turned into a playable “Elden Ring”-style mini game by combining user input, randomness, and conditional logic—then layering in cheats and branching rules to make outcomes feel like a real boss fight. The core idea is simple: ask the player for a choice, generate a random “beast” value, and use an `if/else` check to decide whether the player “vanquishes” the boss or “dies.” That decision-making loop is what transforms a one-line script into something interactive.
The build starts with a basic executable shell script (`eldenring.sh`) that prints “you died.” From there, the script gains its first conditional: it prompts the user with “Do you like coffee?” and reads a `coffee` variable. An `if [[ $coffee == "y" ]]` branch prints “you’re awesome,” while an `else` prints “leave right now.” Running the script with `Y` versus `N` immediately changes behavior, demonstrating how Bash conditionals gate different outcomes.
Next comes the game mechanic. For the first boss, the script generates two random numbers between 0 and 1: one for the beast (`beast`) and one for the player’s “attack” (`tarnished`). The win condition is `if [[ $beast == $tarnished ]]`, which yields a 50/50 chance. The script echoes “beast vanquished” on success and “you died” on failure, with `fi` closing the conditional.
The difficulty ramps up for Margit by switching the random range to 0–9, giving a 1-in-10 chance to win. The script also adds `exit 1` when the player loses, forcing a restart—an intentional “you have to try again” loop that mirrors the frustration of hard games.
To make the mini game more “hackable,” the script introduces a cheat code using logical OR (`||`). The player wins if either the random match succeeds or the player types the string `coffee` as the attack value. It then demonstrates logical AND (`&&`) by requiring both conditions to be true (e.g., a numeric comparison plus another check), showing how compound boolean logic changes difficulty and outcomes.
Finally, the script showcases control-flow patterns that scale: nested `if` statements (only root can win) and `elif` chains (alternate winners based on identity, such as a user named Bernard). The last major upgrade adds character classes at the start of the game—samurai, prisoner, or prophet—each with different starting stats (HP, attack, magic). Instead of stacking many `if/elif` blocks, it uses a `case` statement (Bash’s switch-like construct) to assign class-specific parameters cleanly, then prints the chosen class and stats.
By the end, the script isn’t just a toy example—it’s a structured template for interactive command-line games: input → randomness → conditional branching → escalating rules → class-based stats. The takeaway is that Bash can do far more than print text; with conditionals and a bit of math, it can run decision-heavy logic that feels game-like.
Cornell Notes
The script turns a simple Bash file into an “Elden Ring”-style boss battle by using conditionals, randomness, and user input. It starts with an `if/else` coffee prompt, then uses `if [[ $beast == $tarnished ]]` to decide whether the player wins or “dies.” Difficulty increases by changing the random range (50/50 for the first beast, then 1-in-10 for Margit). It adds cheats with `||` (win if the random match OR the user types `coffee`) and demonstrates stricter logic with `&&`. The final upgrade assigns player classes (samurai/prisoner/prophet) using a `case` statement to set HP, attack, and magic cleanly.
How does the script convert user input into branching behavior in Bash?
What mechanism creates the boss-fight win/lose randomness?
How do `||` and `&&` change the meaning of a win condition?
What’s the difference between nested `if` and `elif` in the script’s logic?
Why use `case` for class selection instead of many `if/elif` blocks?
Review Questions
- In the first boss fight, what exact comparison determines victory, and what random range produces the 50/50 chance?
- How does the cheat code work using `||`, and what would change if it were replaced with `&&`?
- When would a nested `if` prevent a win even if the outer `if` condition is true?
Key Points
- 1
Start with an executable Bash script and a shebang, then build interactivity by prompting for input and storing it in variables with `read`.
- 2
Use `if/else` conditionals with `[[ ... ]]` to branch behavior based on user input (e.g., coffee prompt).
- 3
Implement boss fights by generating random integers with arithmetic expansion and modulo, then compare player and beast values to decide win vs. death.
- 4
Increase difficulty by changing the modulo range (e.g., 0–1 for 50/50, 0–9 for 1-in-10).
- 5
Add “game cheats” by extending win conditions with logical OR (`||`) so alternate inputs can override randomness.
- 6
Use logical AND (`&&`) when multiple conditions must all be true for a branch to run.
- 7
Scale decision logic with nested `if`, `elif` chains, and `case` statements to keep the script maintainable.