So, let's say that I have a command, foo
, in a script which has both a return value, and an output string that I'm interested in, and I want to store those into a variable (well at least its output for the variable, and its return value could be used for a conditional).
For example:
a=$(`foo`) # this stores the output of "foo"
if foo; then # this uses the return value
stuff...
fi
The best thing that I could think of to capture that output is to use some temporary file:
if foo > $tmpfile; then
a=$(`cat $tmpfile`)
stuff...
fi
Is there anyway I could simplify that?