In large software projects we often want to find out in which source
files a certain variable is defined and/or used. Write a
bash
shell script sourcecode.sh
that takes
three arguments:
The script has to look up the text files that contain the given variable. Only files within the given directory (and subdirectories) whose name ends with the given extension must be searched. For every source code line that contains the variable, the script has to write a line to standard output, containing the following three fields (separated by a colon):
Note: the output must be sorted according to file name (alphabetically, increasing) and in case of equal file name the output must be sorted according to line numbers (increasing).
$ sourcecode.sh /usr/lib py spam
/usr/lib/python2.5/site.py:36:with three subdirectories, foo, bar and spam, a...
/usr/lib/python2.5/site.py:56:because bar.pth comes alphabetically before foo...
/usr/lib/python2.5/cgitb.py:32: return <!--: spam
$ sourcecode.sh /usr/share pl foobar
/usr/share/doc/swig2.0-examples/test-suite/perl5/exception_order_runme.pl:18:...
/usr/share/doc/swig2.0-examples/perl5/multiple_inheritance/runme.pl:15:print ...
/usr/share/doc/swig2.0-examples/perl5/multiple_inheritance/runme.pl:16:$foo_B...