Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here are the requirements for this assignment: Using the text editor of your cho

ID: 3687749 • Letter: H

Question

Here are the requirements for this assignment:

Using the text editor of your choice (vi or nano), create a shell script named myscript.sh

Write some code in myscript.sh that will create 50 empty text files in the current directory, named file001.txt to file050.txt

Add some code to myscript.sh that will insert the text "This is file number xxx." (where the "xxx" is the number of that file) into each file - except file007.txt, which shall remain empty

Hint #1: Use a loop to create the files and insert the text into the files - both can be done in the same loop, if you desire.

Hint #2: Use a redirect to echo text into the files.

Hint #3: Use the "touch" command (touch filename.txt) or simply the redirect operator by itself (> filename.txt) to create empty files.

Hint #4: Use a conditional statement to prevent your script from writing text into file007.txt.

Explanation / Answer

#!bin/sh
a=1
while [ "$a" -lt 51 ] # this is loop1
do
if [ "$a" -lt 10 ];then
if [ "$a" -ne 7 ];then
echo "This is file number 00$a " > file00$a.txt
else
touch file00$a.txt
fi
else
echo "This is file number 0$a " > file0$a.txt
fi
a=`expr $a + 1`
done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote