[M3devel] moving versions into simple text file (sh?)

Roland Illig roland.illig at gmx.de
Fri Apr 25 09:20:28 CEST 2008


I'm explaining my code for getting the version numbers into a shell 
script, since it is not completely obvious.

Roland Illig schrieb:
> # usage: get_version VARNAME
> get_version() {
>   eval "gv__set=\${$1+set}"

This code tests whether VARNAME is already defined. When it is, gv__set 
will become "set", otherwise the empty string.

>   if [ "$gv__set" != "set" ]; then
>     gv__value=`awk '$1 == "'"$1"'" { print $2 }' $root/scripts/version`

The awk script compares the first field ($1) of each line with VARNAME, 
and if they are equal, prints the second field ($2). The funny quotes 
("'") are used to insert a shell variable ($1, the first argument to the 
function) literally into the awk script.

>     eval "$1=\$gv__value"

Finally, the VARNAME variable gets the value that has been read from the 
file. If there was no value, the empty string is used.

>   fi
> }

Roland




More information about the M3devel mailing list