Will513r / command-line-VWC

1 stars 0 forks source link

Write a simple shell script #20

Closed Will513r closed 12 months ago

Will513r 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

Will513r commented 1 year ago

Created a shell script that prints hello world which is a variable using nano to create the auto sh file. echo to print and chmod to make it executable.

#!/bin/bash

message="hello world"

echo $message
tupleHunden commented 1 year ago

šŸ‘šŸ»