![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error with if statement..Please help | jisha | Shell Programming and Scripting | 1 | 01-16-2008 07:13 AM |
| while read loop w/ a nested if statement - doesn't treat each entry individually | littlefrog | Shell Programming and Scripting | 7 | 12-11-2007 09:49 PM |
| if statement in a while loop | bobo | UNIX for Dummies Questions & Answers | 2 | 11-07-2006 12:38 PM |
| if statement in for loop of a string | Sniper Pixie | UNIX for Dummies Questions & Answers | 7 | 03-02-2006 07:28 AM |
| tar error statement | legato | UNIX for Dummies Questions & Answers | 3 | 03-29-2005 09:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
For loop statement - catch error
I'm having a question about for loops. (bash)
I have the following for example: for file in `ls *.txt` do read file ... done Now when there is a file present there is no problem, now when there is no file present I get the following output in my standard mail box : "No such file or directory" Script is executed via crontab. Now I want to catch the above error so I don't get it in my mail any more, but I have no idea how to do this. I can make an if statement first "if [ -f *.txt ] ...", but there must be a better solution. Thx. |
|
||||
|
Quote:
Code:
for file in *.txt
do
if test -f $file
then
read file ...
fi
done
|
|
||||
|
Thx for the answers.
I used the solution with the function, now I don't get any "No such file or directory" output anymore. Thx for the help cfajohnson. |
| Sponsored Links | ||
|
|