I/O redirection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I/O redirection
# 15  
Old 03-09-2011
Interesting data and I'm glad you caught my error. But this still leaves the original question up in the air. What are your thoughts on the example the OP asked about? There doesn't seem to be much hope of saving it. Smilie
# 16  
Old 03-10-2011
Quote:
Originally Posted by Perderabo
Interesting data and I'm glad you caught my error. But this still leaves the original question up in the air. What are your thoughts on the example the OP asked about? There doesn't seem to be much hope of saving it. Smilie
I don't know, I asked on c.u.s., this is the releveant part of the Advanced Bash-Scripting Guide:

Code:
# Redirecting only stderr to a pipe.  
exec 3>&1                              # Save current "value" of stdout. 

ls -l 2>&1 >&3 3>&- | grep bad 3>&-    # Close fd 3 for 'grep' (but not 'ls'). #              
               ^^^^   ^^^^
exec 3>&-                              # Now close it for the remainder of the script.  

# Thanks, S.C.

I think S.C. stands for Stephane Chazelas, he's one of the most respected contributors there on c.u.s. (comp.unix.shell).

---------- Post updated at 11:05 AM ---------- Previous update was at 07:41 AM ----------

Got an answer from Icarus Sparry.
This User Gave Thanks to radoulov For This Post:
# 17  
Old 03-10-2011
Quote:
Originally Posted by Icarus Sparry
The "3>&-" just to the left of the comment does close fd 3 for grep but not ls. There is a second 3>&- just to the left of the pipe that closes it for the shell that will turn into ls.
Wow. Duh! That seems so obvious now. Personally, I wasn't able to make sense out of "# Close fd 3 for 'grep' (but not 'ls'). #" because I took it as referring to the entire pipeline, not just the final component (just like, I suspect, the OP).

It wasn't going to keep me up at night, but thank you, radoulov, for showing us the way out of the box Smilie

Regards,
Alister
# 18  
Old 03-10-2011
Quote:
Originally Posted by alister
Wow. Duh! That seems so obvious now. Personally, I wasn't able to make sense out of that comment because I interpreted took it as referring to the entire pipeline, not just the final component (just like, I suspect, the OP).
Me too Smilie

Quote:
It wasn't going to keep me up at night, but thank you, radoulov, for showing us the way out of the box Smilie
You're welcome Smilie
# 19  
Old 03-10-2011
Thanks all of you,you guys are so kind!!And i love this forum more because of you guys!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

2. Solaris

solaris redirection

Hi I am using solaris 10. When running a grep command with multiple files the output is the same as the order of the input. As soon as I pipe the output to another command then it seems that standard error takes precedence, over standard output and gets sent to the pipe first. ie grep -c... (7 Replies)
Discussion started by: chronics
7 Replies

3. Shell Programming and Scripting

Redirection

Hello All, I am using the below script to gather various tools running by the user, we have more than 100 tools running on the server so my challenge is to redirect memory & cpu load to the file with the name of the tool.so am using the below script i am stucking how to redirect to the file... (2 Replies)
Discussion started by: ajaincv
2 Replies

4. Shell Programming and Scripting

Redirection question

I want to redirect stderr and have the following peice of code $ cat t1.ksh #!/bin/ksh func2() { diff /tmp/jdlkwjdlkejew /tmp/djlkwejdlewdjew >$OUTPUT_FILE 2>>$ERR_FILE } func1() { let counter=0 while do print -u2 "Error: In main function" func2 let... (1 Reply)
Discussion started by: BeefStu
1 Replies

5. Web Development

Apache redirection

Hello I have a domain where i need a redirection as described below : i.e mydomain.com/t-ABC-048796/sample.jpg must redirect to mydomain.com/jjj/top/8796/sample.jpg As you can see from the source URL (mydomain.com/t-ABC-048796/sample.jpg) i need the last four characters... (2 Replies)
Discussion started by: unimaxlin
2 Replies

6. UNIX for Dummies Questions & Answers

Help with Redirection

Hi Guys, I m new to UNIX and new to this forum. Was wondering if someone can help me understand redirection (standard input output pipeline etc) for starters, not too sure what this would mean who | sort > sortedfile | pr | lp im starting to understand common commands but when throwing... (2 Replies)
Discussion started by: jmack123
2 Replies

7. Shell Programming and Scripting

Perl Redirection

Hi, I have a Perl script that finds some files based on some criteria and then it processes the file contents using some logic. Extract: print "Started ... "; my $command = "<unix command>"; @arr=`$command`; $size=@arr; print "Size: ".$size If I turn on the Perl debugging option then I... (3 Replies)
Discussion started by: King Nothing
3 Replies

8. Shell Programming and Scripting

redirection problem

hi all, how to redirect the stdout msg in command line and file at the same time? e.g i got the script named test.sh, content as following: #!/bin/sh echo "111" when i run the script ./test.sh > log.log, it will wirte the "111" into log.log, but how to show the "111" in command line... (2 Replies)
Discussion started by: eric_wong_ch
2 Replies

9. Shell Programming and Scripting

redirection

Hi, The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale. Now the proble is: How can I redirect stderr to a file? PS: so I want to redirect ALL the errors to a file. I tryed... (9 Replies)
Discussion started by: DNAx86
9 Replies

10. Programming

Help with redirection

Here is my problem. I don't know make this redirection thing work. The output file (called output.c) looks like this #include<stdio.h> int main() { int k; int m; print f("%d\n", k); printf("%d\n", m); return 0; } the input file(called input.c) is this #include<stdio.h> int... (2 Replies)
Discussion started by: Shallon1
2 Replies
Login or Register to Ask a Question