Option parsing with getopts
📖 Scenario: You are writing a simple command-line tool that accepts options to customize its behavior. This tool will accept a name and an age as options and then display a greeting message.
🎯 Goal: Build a bash script that uses getopts to parse -n for name and -a for age options, then prints a greeting message using the provided values.
📋 What You'll Learn
Create variables to hold name and age
Use
getopts to parse -n and -a optionsAssign the option values to the correct variables
Print a greeting message using the parsed name and age
💡 Why This Matters
🌍 Real World
Many command-line tools use option parsing to customize their behavior. Learning <code>getopts</code> helps you build flexible scripts.
💼 Career
Understanding option parsing is essential for scripting tasks in system administration, DevOps, and automation roles.
Progress0 / 4 steps