Shell script that displays number of line in given file

Script:
if [ $# -eq 0 ]
    then
        echo No arguments
else
    for fname in $*
        do
            if [ -f $fname ]
                then
                    echo $fname is a regular file
                    count="wc -l $fname" #wc = word count
                    echo Number of lines in $fname are
                    echo $($count)
            else
                echo $fname is a directory file
            fi
        done
fi

Output:
 root@root:~/os# sh 2d.sh test1
test1 is a regular file
Number of lines in test1 are
10 test1
root@root:~/os# sh 2d.sh test
test is a directory file

Comments

Popular posts from this blog

Multi-programming with variable number of tasks(MVT) program in C

Multi-programming with fixed number of tasks(MFT) program in C

Linked file allocation program in C.