• Source
    1. #
    2. #Write a script that behaves both in interactive and non-interactive mode. When no arguments are
    3. #supplied, it picks up each C program from current directory and lists the first 10 lines. It then prompts
    4. #for deletion of the file. If the user supplies arguments with the script, then it works on those files only.
    5. #
    6. clear
    7.  
    8. args=$#
    9.  
    10. if [ $args -eq 0 ]
    11. then
    12. for i in $(find . -name "*.txt")
    13. do
    14. echo "$(sed -n '1,10p' $i)"
    15. rm -i $i
    16. done
    17. else
    18. for i in $*
    19. do
    20. if [ ! -f $i ]
    21. then
    22. echo "File $i does not exist"
    23. else
    24. echo "$(sed -n '1,10p' $i)"
    25. rm -i $i
    26. fi
    27. done
    28. fi