Get AI summaries of any video or article — Sign up free
BASH scripting will change your life thumbnail

BASH scripting will change your life

NetworkChuck·
4 min read

Based on NetworkChuck's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Start with a simple executable Bash script using a shebang, echo, sleep, and chmod +x to create a repeatable daily routine.

Briefing

A Bash script can do far more than print a motivational message—it can personalize the greeting, pull in live system information, and even fetch dynamic details like IP addresses, weather, and a daily joke. The core idea is to build a “best day ever.sh” script that starts by encouraging the user, then upgrades itself into a small automation tool that feels tailored to whoever runs it.

The walkthrough begins with a simple script that prints three lines (with a customizable name and a “bonus” message), pauses between messages using sleep, and then is made executable with chmod. Running it immediately demonstrates the payoff: the script becomes a repeatable ritual for starting the day. From there, the script is generalized using a variable named “name,” so the same file can greet different people without editing every occurrence of a hard-coded string.

Next comes the first big automation step: instead of manually changing the variable inside the script, the script asks the user for input. Using read, it prompts “What is your name?” and stores the response in the name variable. That single change turns the script into something interactive—anyone can run it and get a personalized greeting.

The lesson then adds command-line flexibility through positional parameters. By accepting arguments after the script name, the script can map the first argument to $1 and the second to $2. A practical example replaces a generic “beard” compliment with a user-supplied second parameter, so the greeting can be customized per person and per message. This is the shift from “one script for one person” to “one script that adapts to whoever calls it.”

Finally, the script evolves again by storing command output inside variables. Using command substitution with $(...), it captures results from whoami, pwd, and date—then prints a longer status line like “You are currently logged in as …” and “You are in the directory …” and “Also today is …”. The script becomes both motivational and informative, combining user input, command-line arguments, and real-time system context.

The closing tease points to an even more elaborate end result: when run, the improved script can report the user’s private IP address, public IP address, the weather for a chosen city, and a dad joke of the day—turning a morning pep talk into a lightweight daily dashboard driven entirely by Bash scripting.

Cornell Notes

The “best day ever.sh” Bash script starts as a simple greeting tool, then becomes interactive and context-aware. Variables let the script reuse a single “name” value across multiple echo lines, avoiding repetitive edits. read prompts the user for input at runtime, while positional parameters ($1, $2, etc.) let command-line arguments customize different parts of the message. The script further upgrades by capturing command output into variables using $(...), pulling in whoami, pwd, and date so the greeting also reports current system context. This matters because these techniques turn Bash from “text output” into practical automation that can personalize and inform every run.

How does a Bash script become personalized without editing hard-coded names everywhere?

It uses variables. The script defines something like name="Patricia" and then replaces repeated text with $name in each echo line. When the variable changes, every place that references $name updates automatically, so only one line needs modification instead of multiple edits.

What’s the difference between setting a variable manually and getting it from the user at runtime?

Manual assignment hard-codes the value inside the script (e.g., name="Patricia"). Runtime input uses read, such as read name, after printing a prompt like “What is your name?”. When the script runs, the user types a value, and read stores it into the name variable for immediate use.

How do positional parameters ($1, $2) make the script customizable from the command line?

Arguments placed after the script name map to positional parameters. For example, running ./best\ day\ ever.sh Abby "eyes" makes $1="Abby" and $2="eyes". The script can then use $1 and $2 in different echo statements, enabling separate customization of the greeting subject and the compliment/message.

How can Bash variables hold the output of commands like whoami or date?

Through command substitution using $(...). For instance, user=$(whoami) stores the output of whoami into a variable, and date=$(date) stores the current date. The script can then echo those variables later, producing a sentence that reflects the system state at runtime.

Why does combining variables, read, positional parameters, and command substitution change what Bash scripts can do?

Together they create a flexible pipeline: read captures interactive input, positional parameters capture command-line customization, variables store reusable values, and command substitution injects live system data. The result is a script that both responds to the user and reflects current environment details, not just static text.

Review Questions

  1. In what situations would you choose read name over using $1 for the user’s name?
  2. Write the command substitution pattern used to store command output in a variable, and name two commands from the lesson that were captured this way.
  3. If a script uses $1 and $2, what happens when you run it with only one argument?

Key Points

  1. 1

    Start with a simple executable Bash script using a shebang, echo, sleep, and chmod +x to create a repeatable daily routine.

  2. 2

    Replace repeated hard-coded strings with variables (e.g., name) so one change updates every greeting line.

  3. 3

    Use read to prompt for input at runtime, making the script interactive for any user.

  4. 4

    Use positional parameters ($1, $2, etc.) to customize parts of the output directly from the command line.

  5. 5

    Capture live command output into variables with $(...) to make the script informative (e.g., whoami, pwd, date).

  6. 6

    Combine input methods (read and positional parameters) with command-derived variables to build scripts that feel personalized and context-aware.

  7. 7

    Extend the concept beyond greetings by adding dynamic features like IP lookup, weather retrieval, and a daily dad joke.

Highlights

A single variable ($name) turns a hard-coded greeting into a reusable script for different people.
read makes the script ask “What is your name?” and automatically plug the answer into the greeting.
Positional parameters ($1, $2) let the same script produce different compliments or messages based on command-line arguments.
Command substitution with $(...) captures whoami, pwd, and date so the output reflects the current system state.
The final concept upgrades the morning message into a mini daily dashboard: IPs, weather, and a dad joke.

Topics

  • Bash Variables
  • read Input
  • Positional Parameters
  • Command Substitution
  • Script Personalization