[Sussex] Trouble with BASH scripting....

Richie Jarvis richie at helkit.com
Mon Feb 20 20:31:06 UTC 2006


Hi Folks,

Having a few problems with a bash installation script I am trying to 
write at the moment, and was wondering if some of our experts might be 
able to give me a hint...

What I want, is a function (called execute) which accepts a series of 
parameters, and executes them.  If they work, great, if they fail, then 
exit the script code 1.

Heres my attempt at this function, but it doesn't always work - some 
commands mess up:

execute() {
       $*
       if [ $? -ne 0 ]
       then
               echo Command Failed: $*
               exit 1
       fi
}

This works fine for simple commands, and even some more complex ones as 
well!

For example:
These all work:
execute sed -e "s/http.*mvpdm/http\\\:\/\/$DM_URL\\\:$DM_PORT\/mvpdm/g" 
mvpdm.properties.tmp > mvpdm.properties
execute unzip -d $STAGE_DIR -o mvpcore* > /dev/null

But this falls flat on its face, and I cannot for the life of me work 
out why (been trying all afternoon!)
execute sed -e "s:.FileHandler.pattern =.*:.FileHandler.pattern 
=$INSTALL_DIR/logs/mvpdm.log:g" logging.properties.tmp > logging.properties

The error it gives is this, which seems to imply to me that something on 
the quoting is going awry, but it works when run from the command line 
(stepping thru the script):
This appears in the logging.properties file:
Command Failed: sed -e s:.FileHandler.pattern =.*:.FileHandler.pattern 
=/home/richie/mvpinstall/logs/mvpdm.log:g logging.properties.tmp
And at the prompt I get this:
sed: -e expression #1, char 22: Unterminated `s' command

So whats going on?

Thanks in advance,

Richie

-- 
Richie Jarvis
Email: richie at helkit.com
Website: http://www.helkit.com
Phone: 0207 100 6879 or 3808676 at sipgate.co.uk





More information about the Sussex mailing list