[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shell redirection success/failure isn't checked
From: |
Jeff Connelly |
Subject: |
Re: Shell redirection success/failure isn't checked |
Date: |
Sat, 28 Aug 2004 14:47:28 -0700 |
On Sat, 28 Aug 2004 10:52:31 -0400, Chet Ramey <chet.ramey@case.edu> wrote:
> Jeff Connelly wrote:
> > Repeat-By:
> > bash-3.00$ dd if=/dev/zero of=junk
> > dd: writing to `junk': No space left on device
> > 276353+0 records in
> > 276352+0 records out
> > bash-3.00$ echo foo>bar
> > bash-3.00$ cat bar
>
> Did you happen to check the return value from `echo'? It will fail,
> though it does not report write errors to stderr.
It does fail ($?=1), but I could have sworn that $? was set to 0. Anyways,
it is /bin/echo returning the error, not the shell.
bug.c:
#include <stdio.h>
int main()
{
printf("output\n");
fflush(stdout);
return 0;
}
bash-3.00$ df .
Filesystem 1K-blocks Used Available Use% Mounted on
/mnt/xxxxxxxx/home 27560740 26160740 0 100% /home
bash-3.00$ gcc /tmp/bug.c -o /tmp/bug
bash-3.00$ /tmp/bug
output
bash-3.00$ echo $?
0
bash-3.00$ /tmp/bug > foo
bash-3.00$ echo $?
0
bash-3.00$ cat foo
bash-3.00$
Further research reveals that bash uses /bin/echo, but the other shell
has its own internal echo, which is why it prints the error. bash is in fact
correctly checking if the open call succeeds:
bash-3.00$ echo foo>bar
bash: bar: Permission denied
and thats all I suppose it can do... it can't check the status of each write(),
its the program's job to do that.
I retract this bug report. Sorry for the waste of time.
-Jeff Connelly