[prog] echoing something to STDERR
Kathryn Andersen
kat_lists at katspace.com
Thu Nov 13 08:49:18 EST 2003
On Wed, Nov 12, 2003 at 11:57:03PM +1100, Jenn Vesperman wrote:
> On Wed, 2003-11-12 at 07:20, Hamster wrote:
> > On Tue, 11 Nov 2003 21:14:39 +0100
> > Hamster <hamster at hamsternet.org> wrote:
> >
> > > [ -f foo.txt ] || echo "foo.txt doesnt exist"
> > >
> > > The problem with this is that echo plonks stuff on STDOUT, I want it to go
> > > to STDERR.
> > >
> > > How do I do that?
>
> You can also try stuff like cat "foo.txt doesn't exist" > stderr.
I assume this is a joke?
Why is this so neat? All you're doing is giving cat your message, which
cat interprets as the name of a file, said file does not exist, and you
get a message
cat: foo.txt doesn't exist: No such file or directory
which would be rather confusing for error messages about things other
than nonexistant files.
Oh, and you also end up with an empty file called "stderr".
I think the original solution (>&2) was neater.
--
_--_|\ | Kathryn Andersen <http://www.katspace.com>
/ \ |
\_.--.*/ | GenFicCrit mailing list <http://www.katspace.com/gen_fic_crit/>
v |
------------| Melbourne -> Victoria -> Australia -> Southern Hemisphere
Maranatha! | -> Earth -> Sol -> Milky Way Galaxy -> Universe
More information about the Programming
mailing list