Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / examples / scripts.v2 / corename
1 #! /bin/bash
2 #
3 # original from:
4 # @(#) corename.ksh 1.0 93/04/01
5 # 92/11/11 john h. dubois iii (john@armory.com)
6 # 92/02/16 Added help option.
7 # 92/02/22 Added cd to origdir to fix prob w/multiple relative paths.
8 # 93/04/01 Added check for whether file exists.
9 #
10 # conversion to bash v2 syntax done by Chet Ramey
11
12 # inspired by belal's equivalent utility
13
14 if [ "$1" = -h ]; then
15     echo \
16 "$0: print the names of executables that dumped core.
17 Usage: $0 [corename ...]
18 If no corename is given, \"core\" is assumed."
19     exit 0
20 fi
21
22 [ $# = 0 ] && set core
23 origdir=$PWD
24 for i; do
25     cd $origdir
26     file=${i##*/}
27     dir=${i%$file}
28     [ -z "$dir" ] && dir=$origdir/
29     if [ ! -f $dir$file ]; then
30         echo "$dir$file: No such file."
31         continue
32     fi
33     if [ ! -r $dir$file ]; then
34         echo "$dir$file: Cannot open."
35         continue
36     fi
37     cd $dir
38
39     # the adb output syntax is highly variable.  this works on SunOS 4.x
40     set -- $(adb $file < /dev/null 2>&1 | sed 1q)
41     name=${7#??}
42     echo "$i: ${name%??}"
43 done