aboutsummaryrefslogtreecommitdiffstats
path: root/examples/scripts.v2/corename
blob: 2b51e5d2f51e1277a62d253782229c7c82033bf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /bin/bash
#
# original from:
# @(#) corename.ksh 1.0 93/04/01
# 92/11/11 john h. dubois iii (john@armory.com)
# 92/02/16 Added help option.
# 92/02/22 Added cd to origdir to fix prob w/multiple relative paths.
# 93/04/01 Added check for whether file exists.
#
# conversion to bash v2 syntax done by Chet Ramey

# inspired by belal's equivalent utility

if [ "$1" = -h ]; then
    echo \
"$0: print the names of executables that dumped core.
Usage: $0 [corename ...]
If no corename is given, \"core\" is assumed."
    exit 0
fi

[ $# = 0 ] && set core
origdir=$PWD
for i; do
    cd $origdir
    file=${i##*/}
    dir=${i%$file}
    [ -z "$dir" ] && dir=$origdir/
    if [ ! -f $dir$file ]; then
	echo "$dir$file: No such file."
	continue
    fi
    if [ ! -r $dir$file ]; then
	echo "$dir$file: Cannot open."
	continue
    fi
    cd $dir

    # the adb output syntax is highly variable.  this works on SunOS 4.x
    set -- $(adb $file < /dev/null 2>&1 | sed 1q)
    name=${7#??}
    echo "$i: ${name%??}"
done