The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting files in one directory matrixtlm UNIX for Dummies Questions & Answers 10 06-15-2007 04:14 PM
Counting number of files in a directory iamalex UNIX for Dummies Questions & Answers 2 09-05-2005 07:13 AM
List files that do not match the search pattern olapxpert UNIX for Dummies Questions & Answers 7 04-14-2005 12:49 PM
List files that do not match the search pattern olapxpert IP Networking 1 04-14-2005 11:37 AM
rm files in a directory, looping, counting, then exit JporterFDX Shell Programming and Scripting 6 07-18-2002 05:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #29  
Old 07-24-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Quote:
+ dev=/biddf/ab6498/dev/ctl
+ cd /biddf/ab6498/dev/ctl
+ echo /biddf/ab6498/dev/ctl
/biddf/ab6498/dev/ctl
+ myfilepattern=CARE01_DLY
+ + date +%Y%m%d
fullpattern=CARE01_DLY_???_20060724
+ typeset -i filecount=0
+ [ CARE01_DLY_AUS_20060724 != CARE01_DLY_???_20060724]
./script4.ksh[11]: test: ] missing
+ [ CARE01_DLY_MKT_20060724 != CARE01_DLY_???_20060724]
./script4.ksh[11]: test: ] missing
+ let 0 == 1
+ print failure
failure
+ exit 1
Sorry, type error
Add a space befor the ] in the test statement whithin the for loop



Code:
#!/bin/ksh
dir=/biddf/ab6498/dev/ctl
export dir
set -x 
myfilepattern=$@
fullpattern=${my_filepattern}_???_$(date +%Y%m%d)
integer filecount=0
for file in $fullpattern ; do
   [ "$file" != "$fullpattern" ] && filecount=$filecount+1
done

if (( $filecount == 10 )); then
print "success"
exit 0
else
print "failure"
exit 1
fi
Reply With Quote
Forum Sponsor
  #30  
Old 07-24-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
You need a space between the " and the ] in:
Code:
[ "$file" != "$fullpattern"]
Perhaps it would be easier for everyone if you familiarized yourself with the syntax of the shell you are using, rather than going back and forth dozens of times about tiny syntax problems. I'm not trying to be rude, just thinking that spooning tiny little pieces to you is less helpful than your taking the time to understand the general concepts of the environment in which you are programming. I've found that many of the experts here tend to give general solutions as a starting point to help you understand your specific problems, which is much more productive than debugging the same script multiple times.
Reply With Quote
  #31  
Old 07-24-2006
Registered User
 

Join Date: Jul 2006
Posts: 183
Jean,

That works perfect!! I just got a question don't the condition need to be reverse of what we have in the for loop condition. I marked it in red. Kindly suggest.

#!/bin/ksh -x
dev='/biddf/ab6498/dev/ctl'
cd $dev
echo $dev

Quote:
#set -x
myfilepattern=$@
fullpattern=${myfilepattern}_???_$(date +%Y%m%d)
integer filecount=0
for file in $fullpattern ; do
[ "$file" != "$fullpattern" ] && filecount=$filecount+1
done

if (( $filecount == 2 )); then
print "success"
exit 0
else
print "failure"
exit 1
fi
Reply With Quote
  #32  
Old 07-24-2006
Registered User
 

Join Date: Jul 2006
Posts: 183
Jean,

I am sorry. I got why we should have negate condition. Thanks for the help.

Once again thanks for your great help.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0