Click to See Complete Forum and Search --> : Err... shouldn't this bit of bash script be correct?


Wallex
10-20-2002, 02:45 AM
#!/bin/bash
valueOk() {
return 0
}
result=valueOk
exit $result

That's all... and it's wrong. exit: bad non-numeric arg `valueOk', if instead of result=valueOk I write result=0 it will work... Hmm.. I don't know what I am doing wrong, I've rechecked a dozen times the bash scripting NHFs and I would say my code is no different from the one used there! So why it still does not works? Have I overlooked something basic?

mingshun
10-20-2002, 03:21 AM
Originally posted by Wallex
#!/bin/bash
valueOk() {
return 0
}
result=valueOk
exit $result

That's all... and it's wrong. exit: bad non-numeric arg `valueOk', if instead of result=valueOk I write result=0 it will work... Hmm.. I don't know what I am doing wrong, I've rechecked a dozen times the bash scripting NHFs and I would say my code is no different from the one used there! So why it still does not works? Have I overlooked something basic?

I think you can try to capture the exit status of the function instead.

i.e:

valueOk
result=$?
exit $result

X_console
10-20-2002, 03:26 AM
The problem is that you're calling the function wrong. In bash you don't use the parentheses when calling the function. Also you must call the function first and then use $? to obtain the return value of the function, like the way mingshun has it.

Wallex
10-20-2002, 02:22 PM
Ah thanks it works now. Hmm... altough I find it ODD that the NHFs on the matter did not said that.. in their own examples they were using var=functionName. Well I can now finish my little script.