Unwanted Error Message on Screen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unwanted Error Message on Screen
# 1  
Old 10-31-2005
Unwanted Error Message on Screen

Below is a part of the script that I wrote when checking whether a file exist in the Internal Disk or not. If a file doesn't exist, how do you get rid of the error message "file or directory does not exist" to show up on screen? Instead, I wanted only the warning message "FILE DOES NOT EXIST IN INTERNAL DISK" that I have setup to appear? Please help me out. Thanks a lot!

#! /bin/csh -f
# fn = filename.
set fn = `cat fn`
#cfn = check filename if it exist in Internal disk.
set cfn = y
while ($cfn == y)
printf "\n\n\n\nEnter filename, `echo $fn` (default) or x (exit): "
set fn = $<

if ($fn == x) then
else
if ( $fn == "" ) then
set fn = `cat fn`
else
echo $fn > fn
endif

ls $SOLHOME/internalDisk/"$fn" | wc -l > cfn
clear

set cfn = `cat cfn`
if ( $cfn == 0 ) then
printf "\n\n\n\n%8s==================================================\n\n"
printf " "\""FILE "\"""$fn""\"" DOES NOT EXIST IN THE INTERNAL DISK\!"\"""
printf "\n\n%8s==================================================\n"
set cfn = y
#end1
end
else
endif
endif
# 2  
Old 11-01-2005
ls $SOLHOME/internalDisk/"$fn" 2> /dev/null | wc -l > cfn

What this does is redirect stderr from the `ls` command to /dev/null (bit bucket) =p

Last edited by supaphat; 11-01-2005 at 09:16 AM..
# 3  
Old 11-02-2005
Unwanted Error Message on Screen

Quote:
Originally Posted by supaphat
ls $SOLHOME/internalDisk/"$fn" 2> /dev/null | wc -l > cfn

What this does is redirect stderr from the `ls` command to /dev/null (bit bucket) =p
I have done the above commands but it gave me this Error Message:
Ambiguous output redirect

I also tried the following:

ls $SOLHOME/internalDisk/"$fn" | wc -l > cfn 2>&errors and gave the same error.
# 4  
Old 11-02-2005
Check out this site. Apparently, you cannot do that!
# 5  
Old 11-02-2005
Why not just use something like this?
Code:
set yourfile="/path/to/yourfile"
if (-e $yourfile) then
 # do something if it exist
else
 # do something if it does not exist
endif

Check the man page for csh for other options.

csh bashers - Smilie
# 6  
Old 11-03-2005
Thanks a lot gentlemen! I will try that!
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Accidentally made a screen within a screen - how to move it up one level?

I made a screen within a screen. Is there a way to move the inner screen up one level so that it is at the same level as the first screen running from the shell? (2 Replies)
Discussion started by: phpchick
2 Replies

2. Shell Programming and Scripting

Getting phone number, its message and assigning them into 2 variables then screen output.

Hi Everyone, I have a flatfile "inbox.txt" which contains some information: Location 0, folder "Inbox", SIM memory, Inbox folder SMS message SMSC number : "+24800000023" Sent : Sat 04 Aug 2012 09:01:00 PM +0700 Coding : Default GSM alphabet... (5 Replies)
Discussion started by: testcase
5 Replies

3. Red Hat

command line tool to disable screen lock and/or screen saver

Hi, I have a simple question : how to disable screen lock and/or sreen saver with command line with RHEL5.4 ? (1 Reply)
Discussion started by: albator1932
1 Replies

4. AIX

AIX power problem cron message on screen

Hello, I keep getting this message even after i removed it from the cron enteries it was added automatically Broadcast message from root@oradb (tty) at 12:00:00 ... rc.powerfail:2::WARNING!!! The system is now operating with a power problem. This message will be walled every 12... (2 Replies)
Discussion started by: filosophizer
2 Replies

5. UNIX for Dummies Questions & Answers

Display message on screen and flat file at same time

Hi guys, I have a script that call another, the other displays de message and I can print directly to the flat file, but in one command I am searchig that this message can be displayed in the screen and in the flat file in one command. I am doing something like this: var=$(./Example.sh)... (2 Replies)
Discussion started by: pipoca
2 Replies
Login or Register to Ask a Question