The following shell script is used to process files in directory test which is l
ID: 3935704 • Letter: T
Question
The following shell script is used to process files in directory test which is located in current working directory It has following features Add a prefix "my" to all c files in directory test E.g Rename test G as my test.c Add an extension "bak" to all txt files in directory test E.g. Rename test txt as test.txt.bak Compile all java files in directory test Count the number of c files in directory test. #1/bin/bash nCfile-0 for dir in i do case "Sdir" in * c) *. txt) eaac done echo there are Sncfile C filea in directory testExplanation / Answer
nCfile=0
for dir in test/* ; do
case "$dir" in
*.c) mv $dir $(printf '%s' "$dir" | sed 's,test/,test/my,')
nCfile=$((nCfile+1))
;;
*.txt) mv $dir $(printf '%s' "$dir" | sed 's,test/,test/my,')
;;
*.java) javac $dir
;;
esac
done
echo there are $nCfile C files in directory test
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.