$ create-and-launch-rocket saturn-mission If you prefer the script to prompt the user for input when it starts, you can use the
read command. Initially, a basic use of read might look like this:
-p option:
read statement, it displays the message “Enter mission name: ” and waits for the user to input the mission name. The entered value is stored in the mission_name variable, and the script continues with that input.
Using the
-p option with read improves user experience by clearly indicating what input is expected.When to Use Command-Line Arguments vs. Prompts
Alternatively, you can combine both methods. For example, you might first check if the mission name is provided as a command-line argument. If not, the script can prompt the user for input. An enhanced version of the script that incorporates both methods is shown below:
In upcoming lessons, we will explore control and conditional statements in shell scripting to design scripts that behave dynamically based on the available input.
read input statements.