3 # erlwareSys: otp/build/beamver,v 1.1 2002/02/14 11:45:20 hal Exp $
5 # usage: beamver <beam_file>
7 # if there's a usable -vsn() attribute, print it and exit with status 0
8 # otherwise, print nothing and exit with status 1
10 # From the Erlang shell:
12 # 5> code:which(acca_inets).
13 # "/home/martin/work/otp/releases/<app>/../../acca/ebin/<app>.beam"
15 # 8> beam_lib:version(code:which(<app>)).
16 # {ok,{<app>,['$Id: beamver,v 1.1.1.1 2003/06/13 21:43:21 mlogan Exp $ ']}}
18 # TMPFILE looks like this:
20 # io:format("hello ~p~n",
21 # beam_lib:version("/home/hal/work/otp/acca/ebin/acca_inets.beam")]).
23 TMPFILE
=/tmp
/beamver.$$
25 # exit with failure if we can't read the file
26 test -f "$1" ||
exit 1
31 [beam_lib:version($BEAMFILE)]).
34 # beam_result is {ok,{Module_name, Beam_version} or {error,beam_lib,{Reason}}
35 beam_result
=`erl -noshell \
36 -s file eval $TMPFILE \
42 # remove brackets and anything outside them
43 # remove quotes and anything outside them
44 # remove apostrophes and anything outside them
45 # remove leading and trailing spaces
49 echo $beam_result |
sed -e 's/.*\[\(.*\)].*/\1/' \
50 -e 's/.*\"\(.*\)\".*/\1/' \
51 -e "s/.*\'\(.*\)\'.*/\1/" \
52 -e 's/ *$//' -e 's/^ *//'