Patch-ID: bash32-044
[bash.git] / examples / scripts.v2 / corename
blob2b51e5d2f51e1277a62d253782229c7c82033bf8
1 #! /bin/bash
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.
10 # conversion to bash v2 syntax done by Chet Ramey
12 # inspired by belal's equivalent utility
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
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
33 if [ ! -r $dir$file ]; then
34 echo "$dir$file: Cannot open."
35 continue
37 cd $dir
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