Friday, January 06, 2006

Using the Return Value

Functions, like programs, succeed or fail. That's what $? is about. (At the shell level, $? tells whether the last command succeeded or failed. Here, as far as the shell is concerned, the function is just like a command.)

This means that if you have a function to check out and build code
get-N-make() {
svn co $*
(
cd $_
make
)
} &> /dev/null
You can call it like this:

get-N-make -Dyesterday mycode ||
die "something in the checkout or build failed"
(Notice that you can redirect the output of a function as part of its definition.

0 Comments:

Post a Comment

<< Home