Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-14
8
Medium Priority
?
758 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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