How to ignore errors in script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to ignore errors in script
# 1  
Old 01-28-2011
How to ignore errors in script

I have a simple script that processes files. Here's a simplified example of what I'm doing:
Code:
foreach t (web.*)
  mv $t dnw$t:e.log
end
 
foreach t (card.*)
  mv $t card$t:e.log
end

The problem is that sometimes there is no web.* file. In that case, I get an error "foreach: No match" and the script terminates.

I don't want the script to terminate. If web.* does not exist, I simply want the script to drop through to the next command, and, in this case, process card.*.

How do I keep the script from terminating and get it to drop through to the next command?

(I'm on a FreeBSD Unix server.)

Thank you.
# 2  
Old 01-28-2011
Insert at head of loop:
Code:
if [ "$t" = "web.*" ]
then
 break
fi

or change loop:
Code:
ls web.* 2>/dev/null | while read t
do
 . . .
done

# 3  
Old 01-28-2011
Please post the output from the command :
Code:
echo "${SHELL}"


(You seem to be posting "csh" commands and DGPickett is posting "ksh" commands).

Last edited by methyl; 01-28-2011 at 08:02 PM..
# 4  
Old 01-28-2011
Yes, methyl, thanks for catching this. I am using c-shell (output from the echo is /bin/csh . Sorry, I should have mentioned that.
# 5  
Old 01-30-2011
Perhaps somebody who knows "csh" or "tcsh" can help out here. Most unix/Linux System Administrators use use Bourne Shell and its many derivatives (ksh; bash; ash; Posix sh; etc.).

You will not find "csh" in any unix or Linux system startup scripts.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ignore .txt in find script

Hi i am really new to linux scripting and i need a little bit help. i have the following script: find "/usr/share/nextcloud/data/__groupfolders" -type f -mtime +14 -exec rm {} \; but i don't want to delete everything. I want to ignore .txt files. How can i do this? (3 Replies)
Discussion started by: Frederic
3 Replies

2. Shell Programming and Scripting

Ignore Folder in Shell Script ?

Hi, I currently use a script to extract *.deb files located in a Directory called "/var/mobile/Media/Downloads" The Problem is howver I want the script to ignore the folder: "/var/mobile/Media/Downloads/New Debs and Files" (it shall NOT decompile any of the files in that folder. Here is... (2 Replies)
Discussion started by: pasc
2 Replies

3. Shell Programming and Scripting

Ignore lines in Shell Script

Hi, I have a shell script, which reads a *.txt file - line by line. In this text file, I have some lines beginning with "#" that I want to ignore : MY_FILE #blah blah blah 1 blah blah blah 2 blah blah blah 3 #blah blah blah 4 I want my script to read only the following lines... (3 Replies)
Discussion started by: ad23
3 Replies

4. UNIX for Dummies Questions & Answers

cp/ditto and ignore I/O errors?

Hi I am copying some old CDs to HD and while copying a lot of them have I/O errors. What I'm doing right now is sudoing the cp command to force the cp to finish but when I do this it takes about an hour to copy 500mb, which without errors would normally take 2-3 minutes. I assume it takes so... (0 Replies)
Discussion started by: dloruss1
0 Replies

5. UNIX for Advanced & Expert Users

Script to ignore word from a line ...

Hi Gurus, I'm need of a script in which we are finding an independent word ‘boy' in a log file. We are using grep in order to do the same. Now in this log file there are some sentences where we see ‘This is a boy' and we do not want to count word ‘boy' from this sentence. So in other word we want... (2 Replies)
Discussion started by: heyitsmeok
2 Replies

6. Shell Programming and Scripting

Make python script ignore .htaccess

I just wrote a tiny script with the help of ghostdog74 to search all my files for special content phrases. After a few modifications I now made it work, but one problem is left. The files are located in public_html folder, so there might also be .htaccess files. So I ignored scanning of that... (4 Replies)
Discussion started by: medic
4 Replies

7. Shell Programming and Scripting

ignore negative number in script

Hi, does anyone know how to ignore whether a number is negative in a script. E.g. if I have a variable that contains -1200, how do I ignore the minus sign? (1 Reply)
Discussion started by: borderblaster
1 Replies

8. UNIX for Dummies Questions & Answers

Forcing Makefile to Ignore Errors

Is there A way I can Force a makefile to ignore errors? i believe it is using gcc. i have a set of commands in the makefile that i want to run and each time the makefile gets to the point of this commands, it aborts because of the commands. how can i get the makefile to keep running... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. Shell Programming and Scripting

Ignore diriectories within a script

Hi there, I have a small issue with a script that I am running. I need it to ignore certain dir when copying over files. Ie the code is pointing towards the dir etest but I need to ignore the dirs INLINE and ENG which is contained within this...could anyone give me a pointer on how to do this? I... (9 Replies)
Discussion started by: lodey
9 Replies
Login or Register to Ask a Question