stottj / Command-Line

0 stars 0 forks source link

Write a simple shell script #26

Open stottj opened 1 year ago

stottj commented 1 year 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