
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] sh bug
On Wed, Feb 19, 2003 at 09:52:03PM -0500, Viktor Pavlenko wrote:
> >>>>> "JDB" == J David Beutel <jdb@example.com> writes:
>
> >> $ sh -c 'while read a; do if [ $a = "b" ]; then exit 1; fi; echo $a; done < a; echo done'
> >> a
> >> done
> >> $ ksh -c 'while read a; do if [ $a = "b" ]; then exit 1; fi; echo $a; done < a; echo done'
> >> a
>
> JDB> What is the bug? The exit only ends the while loop? Or the
> JDB> parser is susceptible to obfuscation?
>
> I was afraid I would have to explain :( But I though it'd be JC :)
>
> sh interprets exit inside the while loop (only if it's fed from stdin)
> as break. This contradicts the man page. Re. obfuscation, I always do
> such things on command line, so that I don't have to save a file and
> make it executable. No intentional obfuscation was intended. Come on,
> it's just one line of code.
>
Are you sure this is not to do with the way sh on Solaris actually
executes the code? ie it will actually sh the if statment. Thus an exit 1
will cause the sub sh to exit. That or the main while loop is executed in
a sub sh, either could cause this. I know this seems silly, but sh on
Solaris is very small and simple in comparison to bash.
</poorexplanation>
Tim.
--
"ergo it is easier to drag sheep downhill" - Applied Ergonomics Magasine
Tim Hurman - Email: kano at kano.org.uk - Phone: Yeah right.
Home |
Main Index |
Thread Index