[CALUG] Bourne shell block parameters

Jim Sansing jjsansing at verizon.net
Wed Sep 12 09:49:06 EDT 2007


The eval builtin command should work:

  eval ${*} > ${OUTPUT} 2>&1
  RETCODE=$?
  ...
  return $RETCODE

(Is that simple enough for you? ;-)

Later . . .   Jim

Jason C. Miller wrote:
> 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
> ------------------------------------------------------------------------
>
> _______________________________________________
> CALUG mailing list
> CALUG at unknownlamer.org
> http://unknownlamer.org/cgi-bin/mailman/listinfo/calug
>   




More information about the CALUG mailing list