Part 3 Fill in the blanks. The following shell script is used to process files i
ID: 3935517 • Letter: P
Question
Part 3 Fill in the blanks.
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.c as mytest.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.
#!/bin/bash
nCfile=0
for dir in `______________` ; do
case "$dir" in
*.c) _______________________
_______________________
;;
*.txt) _______________________
;;
_______ _______________________
;;
esac
done
echo there are $nCfile C files in directory test
Explanation / Answer
nCfile=0
for dir in * ; do
case "$dir" in
*.c) fspec2=$(echo my${dir})
mv ${dir} ${fspec2}
((nCfile+=1))
;;
*.txt) fspec2=$(echo ${dir}.bak)
mv ${dir} ${fspec2}
((nCfile+=1))
;;
*.java)
javac ${dir}
;;
esac
done
echo there are $nCfile C files in directory test
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.