Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   csh suppress output; newbie question (http://www.programmingforums.org/showthread.php?t=3446)

jolok Apr 19th, 2005 10:08 AM

csh suppress output; newbie question
 
This is a simple question, but it's giving me problems...


I have:
:

if( -e $HOME/*.core ) then
    rm -f $HOME/*.core &> /dev/null
  else
    echo "No core file"
endif

When I run the script I get: /home/<user>/*.core: no match

How can I suppress the output from the rm command? Thanks in advance.

spydoor Apr 19th, 2005 3:07 PM

redirect STDERR

apparently in csh there is no standard way to do it, but there are ways..

http://www.codecomments.com/Unix_Pro...age452517.html

jolok Apr 19th, 2005 3:24 PM

I should've mentioned that I tried that, first.

:

if( -e $HOME/*.core ) then
    rm -f $HOME/*.core 2> /dev/null
  else
    echo "No core file"
endif


/home/<user>/*.core: no match :(

And, from man rm(1):
-f Attempt to remove the files without prompting for confirma-
tion, regardless of the file's permissions. If the file does
not exist, do not display a diagnostic message or modify the
exit status to reflect an error. The -f option overrides any
previous -i options.

So it shouldn't echo stderr anyway, should it?

Also, redirecting both stderr and stdout (which I was trying to do incorrectly in the first example) doesn't help, either:

:

if( -e $HOME/*.core ) then
    rm -f $HOME/*.core >& /dev/null
  else
    echo "No core files to delete"
endif


the 'else' never gets a chance...

I'll try again without any redirection...
No dice. Same result. Also, from the command line (csh) rm displays the same behavior.
JoloK

spydoor Apr 19th, 2005 3:33 PM

sorry, I was thinking ksh.

I editied my post what you want is, >&

also yes, It looks like with -f there should be no error msg to worry about.

Maybe I should've left this one to someone with more knowledge......

spydoor Apr 19th, 2005 3:45 PM

Okay the -f does suppress the error message.

The
:

/home/<user>/*.core: no match
is actually coming from your

:

(-e $HOME/*.core)
statement

jolok Apr 19th, 2005 4:01 PM

Ah! Ok, I was orginally trying different test variables there... I'll work on it from that angle. Thanks, spydoor!


JoloK

spydoor Apr 19th, 2005 4:16 PM

Here's a nasty solution.... There must be much better ways

count the number of files that match *.core... ignore 'No match'...
(to be correct you would also have to ignore other find error msgs like Permission denied.....)

:

if(`find $HOME/*.core |& grep -v 'No match' | wc -l`) then
    echo found some
  else
    echo didn\'t find any
endif



All times are GMT -5. The time now is 3:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC