Summary
In this challenge, you learned how to create a simple shell script that uses a for
loop to iterate through a list of files in a directory and perform an operation on each file. You practiced writing a script that accepts a command-line argument, checks if the argument is valid, and then processes the files in the specified directory. This challenge helps you develop the skills to create more complex shell scripts that can automate various tasks and handle dynamic input.
If you need to set up the initial environment for this challenge, you can use the following setup.sh
script:
#!/bin/bash
## Create some sample files in the ~/project directory
mkdir -p ~/project
echo "Content of file1.txt" > ~/project/file1.txt
echo "Content of file2.txt" > ~/project/file2.txt
echo "Content of file3.txt" > ~/project/file3.txt
You can run this script as the labex
user to set up the initial environment for the challenge.