On Mon, 24 Feb 2003, Michael Torrie suggested we build a large wooden badger:
> On Mon, 2003-02-24 at 16:48, Stuart Jansen wrote:
> > On Mon, 2003-02-24 at 12:17, Michael Ryan Byrd wrote:
> > > So I decide I want to show all the index.html files on my system with:
> > > 
> > > ls -alR |grep "index.html" 
> > > 
> > > (I could have used 'Find . -name "index.html" -print', but anyway.)
> > > 
> > > The problem is that this command is not executed as root, so I'm going to get a
> > > bunch of errors like:
> > 
> > Two solutions have already been given. However, I personally think the cleanest is
> > 
> > ls -alR 2>/dev/null | grep "index.html"
> 
> That's the exact same as ls -alR | grep "index.html" 2> /dev/null.
> 
> In either case grep doesn't process standard error.  It really doesn't
> matter where on the commandline you put the 2> /dev/null.  I don't think
> it matters where you put 2>&1 either if you really need to parse the
> error stream.
> 
> Note that in the case of the original poster he's using csh, which
> doesn't have the same syntax for redirection and thus 2> is illegal. 
> Anyone know how to do it?

In csh, you can redirect stdout with ">", or both stdout and stderr with 
">&", but there isn't a great way to redirect just stderr.  If you put the 
command inside parens (), it runs it in a subshell.  You can use this to 
redirect inside the subshell, then throw away everything outside:

( ls -alR | grep "index.html" > /tmp/output ) >& /dev/null

This will put the results (stdout) into /tmp/output

Of course, if you really wanted to, you could always do something like 
this to display stdout:
mkfifo /tmp/output
tail -f /tmp/output & 
( ls -alR | grep "index.html" > /tmp/output) >& /dev/null
kill %1
rm -f /tmp/output

I've managed quite a few useful scripts in tcsh.  In some respects, its
syntax is more sane than some languages, however it's really not quite as
powerful for scripting.  Then again, if you're going to do much scripting,
you ought to use bash, perl, python, php, 
<insert_other_scripting_language_here>, or emacs.

Frank
---------------------------------------------------------------------------
Frank Sorenson - KD7TZK
CSR Computer Science Department
Brigham Young University
[EMAIL PROTECTED]


____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://phantom.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to