redirecting standard error in Bash [Archive] - C Board

PDA

View Full Version : redirecting standard error in Bash


wozza
07-15-2002, 10:01 PM
Hi,
How do I redirect standard error in Bash?
I know 2> is what you use in tcsh for redirecting standard error to a file but what is it in Bash?
What about standard output in Bash?

Thanks

ygfperson
07-15-2002, 11:46 PM
cat error >& output.txt
that will redirect both standard output and standard error output to output.txt

standard output is just plain old >

//edit: 2> works with stderr only

wozza
07-16-2002, 03:26 AM
ok thanks, now Ive moved on to the duplicate stuff where you use 2>&1 meaning 2 is the duplicate of 1
what is happening with these two similar scripts using that example?

2>&1 cat x junk 1> junk2

1> junk2 2>&1 cat x junk

Assume junk exists but file x does not exist

Thanks

raimo
07-16-2002, 04:55 AM
This does nothing: 2>&1 because the &1 references to itself.

cat x junk 1> junk2
This will print "cat: x: No such file or directory" and prints junk to junk2(because stderr is not redirected)