Redirecting And Piping


Table of Contents

Stderr 
Redirect stderr to file 
Redirect to stderr 
Redirect stderr to pipe, standard 
Redirect stderr to pipe, filtered 
Redirect 
official way 
quick way 
Redirect stderr and not stdout? 
sh - write to stderr 
cat from script and file 
Is it possible to diff $variable1 $variable2? 
nice and pipe commands 
Stupid shell script question about "read" 
Stupid shell script question about "read" 
Stupid shell script question about "read" 
Stupid shell script question about "read" 
Stupid shell script question about "read" 
Stupid shell script question about "read" [SOLVED] 
Stupid shell script question about "read" [SOLVED] 
Interactions in pipe command 
Interactions in pipe command 
redir stdin 
show pipe result in new xterm 
Shell, pipe, input, etc… 
Working directly with file descriptor 
Obtain return code before pipe 
Obtain return code before pipe 
Obtain return code before pipe 
conditional piping 
conditional piping 
conditional piping 
sh trick 
pipe only if exit status is oK 
pipe only if exit status is oK 
sh foo vs. sh < foo 
"eval" is in background? 

Stderr 

Redirect stderr to file 

cmd 2> file

Redirect to stderr 

echo "Message..." >&2

Redirect stderr to pipe, standard 

There is no way to pipe only stderr. If want to pipe stderr, stdin has to go through too:

prog 2>&1 | prog2

documented on: 2005.05.25

Redirect stderr to pipe, filtered 

As explained before, if you want to pipe stderr the standard way, stdin has to go through too.

However, if you really want to pipe only stderr through, without stdin messing up the content, this is how:

$ ls -d . no
ls: no: No such file or directory
.

ls -d . no 2>&1 > log1 | cat > log2

$ cat log1
.

$ cat log2
ls: no: No such file or directory

I.e., the file log2 contains output only from the stderr of the first command.

documented on: 2007.04.03