mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Not successful if statements returning error code
@ 2021-07-23 10:18 Andrej Picej
  2021-07-27  5:20 ` Andrej Picej
  2021-07-28  8:56 ` Ahmad Fatoum
  0 siblings, 2 replies; 7+ messages in thread
From: Andrej Picej @ 2021-07-23 10:18 UTC (permalink / raw)
  To: Barebox List

Hi all,

I have a question about Hush shell and the use of its conditional 
statements.
We have come upon an interesting behaviour with its return values.

If the condition of the if statement is not true then the return value 
is 1 (error code), and if the condition is true the return value is 0 
(success).

Simple test:
> #!/bin/sh
> if [ 0 -gt 1 ]; then
>   echo "0 gt 1, Ret: $?"
> fi
> echo "Ret: $?"
> 
> if [ 2 -gt 1 ]; then
>   echo "2 gt 1, Ret: $?"
> fi
> echo "Ret: $?"

Output:
> Ret: 1
> 2 gt 1, Ret: 0
> Ret: 0

This means that if, for example the first if statement (where condition 
is not met) would be at the end of a script the return value of that 
whole script would be 1 (error code).
I don't think this follows standard shell behaviour. If if statement 
condition is not met this doesn't mean that the return value should be 
an error code, right?
Using other shells (bash for example) we can see that the returned value 
in both cases is 0, which is expected (IMO).

This behaviour is not new to the Hush or barebox as I could reproduce it 
on various previous barebox versions (2013.08.0, 2017.12.0 and 2019.11.0).

Of course, this problem can be easily avoided if at the end of every 
script we use explicit exit 0. This is doable, but a little annoying.

Although this is not a deal-breaker for us, I was wondering what is the 
reason behind this? How do you get around this and are there any plans 
to fix/modify this in the future so it follows the behaviour of other 
shells?

Thank you for your answer.

Best regards,
Andrej

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-09 10:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 10:18 Not successful if statements returning error code Andrej Picej
2021-07-27  5:20 ` Andrej Picej
2021-07-28  8:56 ` Ahmad Fatoum
2021-07-28  9:38   ` Denis Osterland-Heim
2021-07-29  9:22     ` Ahmad Fatoum
2021-07-29  9:48       ` Denis Osterland-Heim
2021-08-09 10:54         ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox