In this lesson, you’ll learn how to use command-line arguments in shell scripts to make them more flexible and reusable. Previously, our script was hard-coded with the mission name, which meant that launching a rocket for a different mission required manual edits to the code. By incorporating command-line arguments, you can pass the mission name directly when executing the script, dramatically streamlining the process. When a shell script runs, it automatically splits the command and its arguments. The script name is stored in the variableDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
$0, while the first user-provided argument is stored in $1. Subsequent arguments are held in $2, $3, and so on. By replacing hard-coded values with these built-in variables, your script becomes universally reusable for any mission.
Using meaningful variable names (like
mission_name instead of $1 everywhere) improves the readability and maintainability of your code.$1) to a variable called mission_name. This substitution makes the code reusable for any mission, eliminating the need for manual changes before each run.
Always design your scripts to be self-contained and reusable by allowing user inputs through command-line arguments rather than hard-coding values. This approach minimizes errors and improves efficiency.
