# shell program- how many times a function is called

**URL:** <https://community.unix.com/t/shell-program-how-many-times-a-function-is-called/307266>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [March 27, 2012, 5:25pm UTC](https://community.unix.com/t/shell-program-how-many-times-a-function-is-called/307266 "2012-03-27T17:25:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oana06](https://community.unix.com/user_avatar/community.unix.com/oana06/32/7856_2.png) [@oana06](https://community.unix.com/u/oana06)\
**Post date:** [March 27, 2012, 5:25pm UTC](https://community.unix.com/t/shell-program-how-many-times-a-function-is-called/307266/1 "2012-03-27T17:25:50Z")

</div>

We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call.  
I've tried something like this:

```nohighlight
#!/bin/sh

for i in $*;do
    if ! [$i.c]
    then 
    echo $i is not a C file.
    else echo $i is a C file.
    fi
    echo "enter the string to search:"
    read string
    u=`grep -c $string $i`;
    v=`grep -n $string $i`;
        if [$u -gt 0] 
        then 
            { echo $i contains the searched function, $u times.
            echo $v
            }
        else echo ERROR- the file does not contain that function.
        fi

done

```

but for eg. if I give a file that isn't C source it doesn't show the right message.  
also I'm not very sure that this is the right way to solve this problem, because it only works for the functions that you read from the keyboard , not for each function that you have in your program.  
so if you have other ideas please help.  
thank you. and sorry for my bad exprimation.
