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. :)
<br><br>For example....<br>****************************************************************************************<br># The function<br>run_block()<br> { <br> ${*} >${OUTPUT} 2>&1 # Run the block of code
<br> if [ $? != '0' ]; then # Did it run successfully?<br> echo ">>>>> ERROR DUMP >>>>>"<br> cat ${OUTPUT}<br> echo "<<<<< END DUMP <<<<<"
<br> return 1<br> else<br> return 0<br> fi<br> }<br><br><br># The mainline <br># All it does is goes to a directory and untars a file.<br>run_block ( cd random_dir && tar xvf blah.tar ) && echo "All done"
<br>****************************************************************************************<br><br>I'm hoping that this isn't something that's really simple that I'm overlooking.<br><br> -j
<br>