jbeadling / module-1

Command line module
0 stars 0 forks source link

Write a simple shell script #20

Open jbeadling opened 11 months ago

jbeadling commented 11 months ago

Summary

Learn how to write a simple shell script to automate a series of commands. This introduction will cover the basics of scripting, including variables, loops, and conditionals.


Description


Learning Tasks

  1. Introduction to Shell Scripting:

    • Learn what a shell script is and how it can help automate repetitive tasks.
  2. Writing a Basic Script:

    • Understand the components of a shell script, including shebang, comments, variables, and commands.
  3. Running a Shell Script:

    • Learn how to give execute permission to the script and how to run it in the shell.
  4. Hands-on Practice:

    • Exercise 1: Create a new shell script file with a .sh extension. Add the shebang line at the top, #!/bin/bash.
    • Exercise 2: Write commands in the shell script to create a new directory and navigate into it.
    • Exercise 3: Use variables to store the directory name and echo a message.
    • Exercise 4: Add conditional statements to check if the directory already exists before creating it.
    • Exercise 5: Make the script executable using chmod +x script_name.sh and run it with ./script_name.sh.
  5. Troubleshooting:

    • Discuss common issues that can arise while writing and running shell scripts and how to debug them.

Learning Goals


Priority

jbeadling commented 11 months ago

In the screen shots below I show the script I made described in the exercises and the script being used as well.

Image

Image