Part 3 Fill in the blanks The following shell script is used

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

Solution


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

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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site