postheadericon Write a script to learn command line argument


Definition : 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.

File Name : ex26.sh


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 "_______________ $filename _______________"
                                    sed -n -e "1,10 p" $filename
                                    rm -i $filename
                        fi
            done
rm temp
fi


0 comments:

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.