Non deterministic behavior in bash
am 10.01.2008 23:40:17 von Guillaume Dargaud
Hello all,
this is a bug I've been noticing for a long time when using bash in cygwin:
some errors happen where they shouldn't (hah!).
Here's a line of a longer script (TimeJump is a compiled C prog):
Time=`$dir/TimeJump $Time +1`
Note: using $(...) leads to the same random error
Here's the corresponding debug output running with +x:
....
++ /home/dargaud/bin/TimeJump 050804 +1
+ Time=
+ '[' '!=' 080109 ']'
/home/dargaud/bin/TimeLoop2.sh: line 49: [: !=: unary operator expected
But the command "/home/dargaud/bin/TimeJump 050804 +1" _always_ return
050805 so something is deeply wrong. Note that if I run the script a second
time the error will happen on a different value (or may not happen at all).
So basically every once in a while the stdout from my C prog just plain
disappears. WTF ?!?
--
Guillaume Dargaud
http://www.gdargaud.net/
Re: Non deterministic behavior in bash
am 11.01.2008 13:59:07 von Maxwell Lol
"Guillaume Dargaud" writes:
> Here's a line of a longer script (TimeJump is a compiled C prog):
> Time=`$dir/TimeJump $Time +1`
Perhaps you should use
Time=`$dir/TimeJump "$Time" +1`
> ++ /home/dargaud/bin/TimeJump 050804 +1
> + Time=
> + '[' '!=' 080109 ']'
> /home/dargaud/bin/TimeLoop2.sh: line 49: [: !=: unary operator expected
Are you putting "..." around your variables in the [....] statement?
In particular, are you using "$Time" in the test statement?
> So basically every once in a while the stdout from my C prog just plain
> disappears. WTF ?!?
It looks like TimeJump is generating an empty output with the following input
/home/dargaud/bin/TimeJump 050804 +1
I have no idea why.
Re: Non deterministic behavior in bash
am 13.01.2008 23:01:17 von Guillaume Dargaud
You are absolutely right about the quotes in the test... but still, $Time
should never be empty... There's something deeply wrong here and it's either
in my script, in my C or in Cygwin... and I suspect the latter.
I've replaced the line:
Time=$(TimeJump "$Time" +1)
With:
TTT=$(TimeJump "$Time" +1)
if [ "$TTT" = "" ]; then
Time=$(TimeJump "$Time" +1)
echo "This is fscked up"
else
Time=$TTT;
fi
And it has higher probability of succeeding (hah!), but I'm left scratching
my head.
The first line fails about 1% of the time, at random.
Note that I've written this (opejn source) code on IRIX 15 years ago and
used it on Linux for a decade and only now on Windows does it give me
trouble. Talk about improvement...
--
Guillaume Dargaud
http://www.gdargaud.net/