Write a script that behaves both in interactive and non-interactive mode. When no arguments are supplied, it picks up each C program from current directory and lists the first 10 lines. It then prompts for deletion of the file. If the user supplies arguments with the script, then it works on those files only.
flag=1 if [ $# -ne 0 ];then # IF USER PROVIDE ARGUMENTS echo $* >temp flag=1 else # IF USER NOT PROVIDE ARGUMENTS ans=`ls *.c` if [ "" == "$ans" ];then echo "THERE ARE NO C FILE" flag=0 else ls *.c>temp flag=1 fi fi if [ $flag -eq 1 ];then for filename in `cat temp` do if [ -f $filename ];then echo "\t\t\t=========" echo "\t\t\t$filename" echo "\t\t\t=========" echo " " sed -n -e "1,10 p" $filename rm -i $filename fi done rm temp fi
0 comments:
Post a Comment