#!/bin/bash
choice=true
while [ "$choice" != [gG] ]
do
printf '\n\nmenu:\n'
printf ' A. List all files in the present directory\n'
printf " B. Display today's date and time\n"
printf ' C. Display whether a file is a "simple" file or a "directory"\n'
printf ' D. Create a backup for a file\n'
printf " E. Read user's id,then echo the username and the home dierectory\n"
printf ' F. Delete the files ended of ".tmp" in the present directroy.\n'
printf ' G. Exit\n'
printf 'your choice:'
read choice
case "$choice" in
[aA])
ls -al ./*
;;
[Bb])
printf 'time:'
date +%Y/%m/%d/%H:%M:%S
;;
[Cc])
printf 'please input your file name:'
read filename
if [ -f "$filename" ] ; then
printf '%s is a simple file' $filename
elif [ -d "$filename" ] ; then
printf '%s is a directory' $filename
else
printf '%s is not a simple file or directory' $filename
fi
;;
[Dd])
printf 'please input your file name:'
read filename
cp "$filename" ./"$filename"_backup && printf 'create backup succeed,and named %s_backup in the present directory' $filename || printf 'failed,maybe the file is not exsit'
;;
[Ee])
printf 'please input your id number:'
read idnumber
printf 'the username and home directory :'
grep ":$idnumber:[0-9]" /etc/passwd | cut -d ':' -f 1,6
;;
[Ff])
rm -i ./*.tmp && printf 'deleted succeed' || printf 'there are not exsit the files whice ended of ".tmp" int the present directory'
;;
[Gg])
break
;;
*)
printf 'please enter the correct character'
;;
esac
done
printf 'bye\n'
exit 0