Mission Requirements
For our example mission, the requirements are as follows:- Create a directory named “lunar-mission”.
- Create a rocket for that mission.
- Add the rocket using the “rocket-add” command.
- Execute the launch sequence with a series of commands.
- Verify the rocket’s status using the “rocket-status” command.
Creating the Shell Script
Create a file called “create-and-launch-rocket.sh” and move all of the above commands into it in the same order. Choosing a descriptive name for your shell script is crucial. In this example, the script not only creates but also launches a rocket—hence, the name “create-and-launch-rocket.sh” clearly reflects its purpose. Once your shell script is ready, execute it using the bash command. When the script runs, each command is executed sequentially; the script will wait for a command to finish if it takes any time to execute. Here’s an extended version of the commands that might be included in your script:Running the Script as an Executable Command
You can configure your shell script to run like any other command on your system by making it executable. It is a common best practice to omit the.sh extension for commands intended for frequent use.
If you try to run your script immediately after creation, you might encounter an error such as:
Setting Execution Permissions
For your shell script to run properly, you must set the correct file permissions. If you try to run the script without the appropriate permissions, you might see an error like:ls -l command to inspect file permissions. If the execute bit is not set, update the permissions with:
- Choose descriptive script names. Avoid generic names like “script1.sh,” “my_script.sh,” or “test.sh” to make the script’s purpose clear.
- If you plan to use the script as an executable command, consider omitting the
.shextension for a more natural command-line experience.