"Yes Virginia, you can do variable variables in Bash"

| No Comments | No TrackBacks

I was writing a build script in Bash for one of the development projects and I wanted to have a list of patches that would be applied to a "clean" distribution of JBoss to create the fully configured app server.  I needed something simple so the development team could continue to maintain and update the script.  I came up with this idea while looking at RPM building.


#!/bin/bash

PATCH0=$SOURCES/jboss-4.2.3.GA.base.patch
PATCH1=$SOURCES/log4j-setup-append.patch
PATCH2=$SOURCES/jboss-set-call-by-value.patch
PATCH3=$SOURCES/add-security-policy-login.patch
MAXPATCHES=100  #The script searches for PATCH{value}= lines from zero to this number

echo "Applying patches"
i=0
while [ $i -lt $MAXPATCHES ] ; do
  PATCH=$(eval echo $echo PATCH${i});
  if [ ! "$PATCH" == "" ] ; then
    echo "Applying patch: $PATCH"
    patch -p0 < $PATCH
  fi
  i=$[$i+1]
done;


In the end it might have been simpler to use a datafile, or a language with Array support, but this works well enough and is fairly usable.

No TrackBacks

TrackBack URL: http://mindbent.org/cgi-bin/mt/mt-tb.cgi/18

Leave a comment

About this Entry

This page contains a single entry by Mark Farver published on January 3, 2010 2:07 AM.

Quote of the day... was the previous entry in this blog.

I be, you be, Yubikey is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.24-en