[CALUG] Bourne shell block parameters

Jason C. Miller jason.c.miller at gmail.com
Wed Sep 12 07:48:46 EDT 2007


Does anyone know of a way to simulate the passing of a block of code as an
argument to a function in Bourne shell (or even bash)?   I would like to be
able to write an all-encompassing error-checking function that could execute
commands, monitor return status, and return error messages.  I typically do
this as a way to keep my mainline as un-cluttered as possible.  I know that
Ruby programmers will know what I'm asking for.  :)

For example....
****************************************************************************************
# The function
run_block()
  {
    ${*} >${OUTPUT} 2>&1                                # Run the block of
code
    if [ $? != '0' ]; then                                       # Did it
run successfully?
      echo ">>>>> ERROR DUMP >>>>>"
      cat ${OUTPUT}
      echo "<<<<< END DUMP <<<<<"
      return 1
   else
      return 0
   fi
  }


# The mainline
# All it does is goes to a directory and untars a file.
run_block ( cd random_dir && tar xvf blah.tar ) && echo "All done"
****************************************************************************************

I'm hoping that this isn't something that's really simple that I'm
overlooking.

                                                                    -j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.unknownlamer.org/pipermail/calug/attachments/20070912/3f6ea3f7/attachment.htm 


More information about the CALUG mailing list