[M3devel] moving versions into simple text file (sh?)
Roland Illig
roland.illig at gmx.de
Sun Apr 20 09:58:28 CEST 2008
Jay schrieb:
> I'd like to (finally) move the default versions out into a simple file.
>
> Given:
>
> jbook15:/dev2/cm3/scripts jay$ cat version
> CM3VERSION d5.7.0
> CM3VERSIONNUM 050700
> CM3LASTCHANGED 2008-03-16
>
> Is there any chance this is Posix/Solaris compliant?
>
> get_version() {
> if [ -n "$(eval echo \$$1)" ] ; then
> return
> fi
> eval "$1=\"$(echo $(grep "$1 " $root/scripts/version | awk '{print
> $2}'))\""
> }
Solaris' /bin/sh doesn't know the $(...) operator. Why do you need "eval
echo" at all? Better use this:
# usage: get_version VARNAME
get_version() {
eval "gv__set=\${$1+set}"
if [ "$gv__set" != "set" ]; then
gv__value=`awk '$1 == "'"$1"'" { print $2 }' $root/scripts/version`
eval "$1=\$gv__value"
fi
}
$ /bin/sh
$ . ./get_version.sh
$ set -x
$ get_version CM3VERSION
+ get_version CM3VERSION
+ eval __set=${CM3VERSION+set}
__set=
+ [ != set ]
+ awk $1 == "CM3VERSION" { print $2 } version
value=d5.7.0
+ eval CM3VERSION=$value
CM3VERSION=d5.7.0
$ get_version CM3VERSION
+ get_version CM3VERSION
+ eval __set=${CM3VERSION+set}
__set=set
+ [ set != set ]
Roland
More information about the M3devel
mailing list