[prog] Returning a string from a function, in bash

Riccarda Cassini riccarda.cassini at gmx.de
Fri Apr 16 20:16:14 EST 2004

Conor Daly wrote:
> The ways of $? are subtle and likely to bite you unless you know what
> doing[0].  Essentially, $? contains the return value of the last command
> executed.  It's generally useful practice to assign $? to a variable and
then to do
> conditionals based on the variable.  I have a suspicion that my:
> > >   echo `command and result`
> > >   local result=$?
> may itself be flawed since it may be the return code from 'echo' that ends
> up in $result rather than that from `command...`.  If you want the return
> value of a command, run the command, optionally assign the output to a
> variable, and capture the return value.  Only then should you start doing
> fancy stuff with the output.
> Conor (clear as mud??)

I think I got it now :-)   Thanks for explaining!


NEU : GMX Internet.FreeDSL
Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/info

More information about the Programming mailing list