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

I made this batch file: #!/bin/sh #Move to the directory cd $HOME/data/yesh/due/

ID: 3725240 • Letter: I

Question

I made this batch file:

#!/bin/sh
#Move to the directory
cd $HOME/data/yesh/due/File
#Make the files needed
cat > file1/file1.txt

cat > file2/file2.txt

cat > file3/file3.txt

cat > file4/file4.txt

cat > file5/file5.txt

cat > file6/file6.txt

cat > file7/file7.txt

But I need to actually add sentences inside each of the files that the cat command makes. How do I add text to these files in a script? and how do I bypass the (Ctrl + D) to close and save for each file? This prevents all files after the first one from being made.

Explanation / Answer

In given script you need press Cntrl+D each time to sve and close files, because of cat command.

Instead of using cat command go for touch command for create new file.

Sentences can be added into file using below command

echo "message" >> filename  

(Note : '>' is for overwrite text and '>>' for append text into file)

New script (No need to press Cntrl + D ):

#!/bin/sh
#Move to the directory
cd $HOME/data/yesh/due/File
#Make the files needed
touch file1/file1.txt
echo "#Sentence generated by script" >> file1/file1.txt

touch file2/file2.txt
echo "#Sentence generated by script" >> file2/file2.txt

touch file3/file3.txt
echo "#Sentence generated by script" >> file3/file3.txt

touch file4/file4.txt
echo "#Sentence generated by script" >> file4/file4.txt

touch file5/file5.txt
echo "#Sentence generated by script" >> file5/file5.txt

touch file6/file6.txt
echo "#Sentence generated by script" >> file6/file6.txt

touch file7/file7.txt
echo "#Sentence generated by script" >> file7/file7.txt

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