Using Command Line Arguments
One approach is to pass the mission name as a command line argument when executing the script. The script retrieves the first argument (i.e., $1) and uses it as the mission name. This method is especially useful when you want the script to run without manual intervention.Prompting for Input with the read Command
For scenarios requiring interactive input, theread command is an effective option. The following examples illustrate two variations: one without a custom prompt and another with a clear, guiding message.
Without a Custom Prompt
When you useread without the -p option, the script simply waits for input without displaying any guidance. This approach is straightforward but may be less user-friendly.
With a Custom Prompt
To improve clarity, you can add a custom message using the-p option with the read command. This modification makes it evident what input is expected.
mission_name variable and subsequently used in the launch sequence commands.
For enhanced usability, consider designing your script to support both methods. If a command line argument is provided, use it. Otherwise, prompt the user interactively. This approach offers flexibility and makes your script suitable for both manual and automated scenarios.
Choosing the Appropriate Method
When developing your script, consider the following:- For simple scripts that rely on manual user input, using the
readcommand with a custom prompt is ideal. - For scripts designed to operate without human intervention or to be called by other scripts, command line arguments provide a seamless and efficient solution.
Summary
In this session, you learned to capture inputs in shell scripts using two methods:- Command line arguments for unattended runs.
- The
readcommand (with and without a custom prompt) for interactive user input.