#!/bin/bash
#
# find broken links in current directory
# version from class
#
# caution:  does not cope well with names containing spaces
#

# loop over all links
for link in `find . -type l`
do
    file_cmd_out=`file $lnk`
    echo $file_cmd_out | grep "broken symbolic link" >/dev/null 2>&1
    if [ "$?" -eq 0 ]
    then
        echo broken link $lnk
    fi
    if echo $file_cmd_out | grep "broken symbolic link" >/dev/null 2>&1
    then
        echo broken link $lnk
    fi
done
