I have a script, that reads some input foo
, and based on that input tries to calculate the value for the variable bar
. If it is successful, then it shall set bar
. If not, the user should be able to input that value for bar
manually.
Currently I have:
read foo
bar=$(some manipulation with foo)
if [ $bar ]
then
echo $bar
else
read bar
fi
The problem I'm experiencing is that in some cases I get more than a single word answer back from the manipulation of foo. I know I could work around that with quotes or the new test, but that's not what I want. I'd like that if some manipulation with foo
returns multiline output, that it asks to set bar
manually. The same reaction as to no answer. How would I do that?
bar
, is it accepted? – eppesuig Feb 04 '14 at 10:02