Skip to content

Instantly share code, notes, and snippets.

@humdingerb
Created May 6, 2018 06:52
Show Gist options
  • Select an option

  • Save humdingerb/82138c9cffad41d65fd83dacc8171eb6 to your computer and use it in GitHub Desktop.

Select an option

Save humdingerb/82138c9cffad41d65fd83dacc8171eb6 to your computer and use it in GitHub Desktop.
A bash script to facilitate grepping libraries
#!/bin/sh
#
# Copyright 2011, Haiku, Inc. All Rights Reserved.
# Distributed under the terms of the MIT License.
#
usage() {
echo `basename $0` \[-V\] \<symbol\>
echo \- list files containing \<symbol\>
echo " -V lists also directories searched"
echo ""
echo `basename $0` -h
echo \- Show this help
exit 0
}
if [ "$1" == "-V" ]; then
VERBOSE=1
shift
else
VERBOSE=0
fi
if [ "$1" == "-h" ]; then
usage
fi
if [ "x$1" == "x" ]; then
usage
fi
LPATH=`echo $LIBRARY_PATH|sed "s|%A/lib:||"`
[ -d ./lib ] && LPATH="./lib:$LPATH" || true
LPATH=`echo $LPATH|sed "s/:/ /g"`
TEMPFILE=/boot/var/tmp/`basename $0`.$PPID
for libdir in `echo $LPATH`; do
if [ "$VERBOSE" == "1" ]; then
echo Searching in \"$libdir\"...
fi
for lib in $libdir/*.so ; do
echo "[ $lib ]" > $TEMPFILE
(nm -D $lib 2>/dev/null)|grep $1 >> $TEMPFILE
LINES=`wc -l $TEMPFILE | awk '{ print $1; }'`
if [ "$LINES" != "1" ]; then
cat $TEMPFILE
fi
done
done
rm -f $TEMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment