Solved

send cshell std out to screen and std error to /dev/null

Posted on 2004-09-14
8
734 Views
Last Modified: 2013-12-26
I want to send the output of find to the screen and std error to the bit bucket using the c shell.
(find / -name foo > somefile) >& /dev/null  will send the output to somefile & then I could use 'cat somefile' to read the file but is there a  way to send the output of find directly to the screen?

0
Comment
Question by:jesplumbob
8 Comments
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 250 total points
ID: 12057745
(find / -name foo > /dev/tty) >& /dev/null
0
 
LVL 19

Expert Comment

by:NickUpson
ID: 12058348
in case /dev/tty is not your screen

find / -name foo 2>/dev/null
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12058447
/dev/tty is _always_ your screen. That's what it does.

Meanwhile, the 2>/dev/null syntax doesn't work in csh, only sh and variants.

One reason few people use csh any more since ksh and bash have had all the main features that people switched from sh to csh n the first place, like history and job control, for over 15 years
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12059414
From the "csh considered harmful"

1a. Writing Files

In the Bourne shell, you can open or dup arbitrary file descriptors.
For example,

    exec 2>errs.out

means that from then on, stderr goes into errs file.

Or what if you just want to throw away stderr and leave stdout
alone?    Pretty simple operation, eh?

    cmd 2>/dev/null

Works in the Bourne shell.  In the csh, you can only make a pitiful
attempt like this:

    (cmd > /dev/tty) >& /dev/null

But who said that stdout was my tty?  So it's wrong.  This simple
operation *CANNOT BE DONE* in the csh.


Along these same lines, you can't direct error messages in csh scripts
out stderr as is considered proper.  In the Bourne shell, you might say:

      echo "$0: cannot find $file" 1>&2

but in the csh, you can't redirect stdout out stderr, so you end
up doing something silly like this:

      sh -c 'echo "$0: cannot find $file" 1>&2'
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 38

Expert Comment

by:yuzh
ID: 12060736
chris_calabrese's comment (http:#12058447) is correct!

Just add a bit more infor to see if I can help you understand it.

In csh/tcsh, you can redirect stdout with ">", or stdout and stderr together with ">&"
but there is no direct way to redirect stderr only. The best you can do is:
        ( command >stdout_file ) >&stderr_file

which runs "command" in a subshell;  stdout is redirected inside the subshell to stdout_file,
and both stdout and stderr from the subshell are redirected to stderr_file, but by this point
stdout  has already been redirected so only stderr actually winds up in stderr_file.

For shell scripting you should use sh/ksh/bash, it is a lot easy to do things than csh/tcsh.

please have a look at "Csh Programming Considered Harmful":
http://www-dbs.inf.ethz.ch/~fessler/csh-whynot.html

BTW, csh was my default login shell 10+ years ago, I changed my default shell to ksh, and
write script in ksh.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12063282
> "Csh Programming Considered Harmful"
and for "bash Programming Considered Harmful":
    :() { :; };:

0
 
LVL 2

Expert Comment

by:rajeshp_69
ID: 12064565

Just try out the following command:

(find ./ -name foo > `tty` ) >& /dev/null

I am sure that this must work for you as I also uses csh for some applications.

Bye
0
 

Author Comment

by:jesplumbob
ID: 12066403
I gave chris' answer an A because it was fast, short and complete. In my case going to bash isn't good because the main reason for my system is to support a high-end CAD app and it requires me to source some scripts that assume the c shell. I could jump back and forth between shells but that's complicated and I like simple.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now