[comp.os.os9] SILENT ERROR exits SHell script?

knudsen@cbnewsd.att.com (michael.j.knudsen) (06/05/91)

Strange thing is happening in OSK on my MM/1.
If I run the DIFF utility in a shell script,
it runs fine but immediately exits the script upon completion.
No error message at all -- it just acts as if the script had
reached normal EOF.

I have not yet tried setting -x to see whether DIFF really is
returning a "silent" error code, but that is so far my only theory.

I know that non-zero error returns will exit a shell script,
but they always print at least the error number.
How is it that DIFF can break out of the script with no error message?

I don't know where this DIFF came from (Microware, or PD, or what),
but it has another bug that may be related.  If you type just
"diff" with no arguments, it responds with
	diff: use: diff file1 file2
ERROR 000:002  Keyboard Abort

or whatever OSK says for when you hit the BREAK key.

I understand this DIFF is buggy and should be replaced with a
better version.  But just for my education, how can it *silently*
force the Shell to exit the script?
Thanks, mike k
-- 
"What America needs is A Thousand Points When Lit..."
	knudsen@ihlpl.att.com

ignatz@wam.umd.edu (Mark J. Sienkiewicz) (06/06/91)

In article <1991Jun4.230458.25390@cbnewsd.att.com> knudsen@cbnewsd.att.com (michael.j.knudsen) writes:
>If I run the DIFF utility in a shell script,
>it runs fine but immediately exits the script upon completion.
>No error message at all -- it just acts as if the script had
>reached normal EOF.

>I know that non-zero error returns will exit a shell script,
>but they always print at least the error number.
>How is it that DIFF can break out of the script with no error message?

Microware's shell exits whenever a process returns a non-zero exit code.
The exit code you are getting is 1 (or 000:001 in microware terms).  This
error seems to get special treatment by not being printed, but only
if you ar executing a script.  Is this weird or what?

>I don't know where this DIFF came from (Microware, or PD, or what),
>but it has another bug that may be related.  If you type just
>"diff" with no arguments, it responds with
>	diff: use: diff file1 file2
>ERROR 000:002  Keyboard Abort

Here are the standard exit codes for diff:
	0 no differences
	1 the two files are different
	2 some error occured

The diff you have is probably either GNU diff or maybe stolen/licensed
from Unix.  This means you should just ignore the goofy error messages
and get on with whatever you are doing.

I would also ask "Why do you have diff in a shell script?"  Microwares
shell doesn't have any way to branch on the result (at least not in
the OS9 I have).  Normally you would write

	if diff filea fileb > /dev/null
	then
		do-something-because-they-are-the-same
	else
		do-something-because-they-are-different
	fi

>I understand this DIFF is buggy and should be replaced with a
>better version.  But just for my education, how can it *silently*
>force the Shell to exit the script?

If you have GNU diff, it is in pretty good shape except that it sometimes
needs a lot of memory.   (of course, OS9 can't swap processes out)

knudsen@cbnewsd.att.com (michael.j.knudsen) (06/08/91)

In article <1991Jun5.184640.4481@wam.umd.edu>, ignatz@wam.umd.edu (Mark J. Sienkiewicz) writes:
> Microware's shell exits whenever a process returns a non-zero exit code.
> The exit code you are getting is 1 (or 000:001 in microware terms).  This
> error seems to get special treatment by not being printed, but only
> if you ar executing a script.  Is this weird or what?

Well, I can see the special treatment of Error #001 as being
forward-looking on Microware's part, in case they ever put
conditional branching in their Shell (along with a few other things
that are way overdue, like command-line args...)
 
> Here are the standard exit codes for diff:
> 	0 no differences
> 	1 the two files are different
> 	2 some error occured

OK -- sure sounds like this diff was intended for Un*x usage.
Why else would it use OS9's BREAK error code?
Still wondering whether the -X switch will keep the OSK script from
exiting whenever the files are different.

> I would also ask "Why do you have diff in a shell script?"

Easy.  I want to diff several file pairs, and concatenate the diffs
into one master file.  Whenever I make an incremental backup, using
DSAVE with the -DR options, I first do a dry run and put the DSAVE
generated script into a temp file, and edit it to do DIFFs between
the new and old versions of the files.  Thus I get a record of
changes.

Anyway, a command that you can't use in a script in case it
actually does some real work (ie, find differences) is pretty silly.
I'll try the -X in the scripyt next time.
-- 
"What America needs is A Thousand Points When Lit..."
	knudsen@ihlpl.att.com