#!/bin/ksh # Final course exercise # Enter while loop until directory name given while : do print -n "Enter a directory name please: " read idir if [[ ! -d $idir ]]; then print Sorry not a directory continue else break fi done # Get a list of files into array files set -A files `ls -l $idir | grep ^- | nawk '{print $9}'` # Show the user all the file names print These are the plain files in the chosen directory:- print ${files[*]} #Ask the user to type a list of files to be processed print -n "Enter filename[s] from above list: " read ifiles #Now process the files for fn in $ifiles do print print Current filename is $fn PS3="What action would you like to take on the file?" select action in Copy Display Backup Quit do case $action in Copy) print -n "Filename to copy to [$fn.bak]:- " read cpfile if [[ $cpfile == "" ]]; then cpfile=$fn.bak fi if [[ -f $cpfile ]]; then print Sorry - $cpfile already exists break fi cp $idir/$fn $cpfile break ;; Display) if file $idir/$fn | grep -i script > /dev/null; then more $idir/$fn else print $fn is not a script fi break ;; Backup) if cmp -s $idir/$fn ~/logback/$fn; then print $fn and ~/logback/$fn are identical print Not copied break else cp $idir/$fn ~/logback fi break ;; Quit) break ;; esac done done