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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need some clarification on for loop in shel script mail2sant Shell Programming and Scripting 1 10-23-2008 10:42 AM
Pick up the return code for every iteration and display the result only once in loop. manas6 Shell Programming and Scripting 1 10-21-2008 08:12 AM
Clarification Shahul Web Programming, Web 2.0 and Mashups 1 08-16-2008 05:05 AM
the given code goes in infinite loop and does not increment variable i mrityunjay22 Shell Programming and Scripting 6 12-26-2007 02:20 AM
Need clarification ravi.sadani19 Shell Programming and Scripting 2 04-13-2007 02:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2008
mail2sant mail2sant is offline
Registered User
  
 

Join Date: Apr 2008
Location: bangalore
Posts: 68
need loop clarification for the below code

for loop for string to check each path file count.
can someone please help me out regarding this..

purpose is that it will gives the number of files inside the that directory..
i am bit confused in doing the loop for the above can someone plz fix.



PATH1=/home/data1
PATH2=/home/data2
PATH3=/home/data3
PATH4=/home/data3


for path in PATH1,PATH2,PATH3,PATH4


for ((i=0 ; i<=10 ; i++ ))

do


p=/path/msg00"${i}"


n=`ls -lrt $p | wc -l`

echo " $p ==$n"



done
  #2 (permalink)  
Old 10-30-2008
BMDan BMDan is offline
Registered User
  
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
Without changing the way your program currently works, try:

Code:
PATH1=/home/data1
PATH2=/home/data2
PATH3=/home/data3
PATH4=/home/data3


for path in $PATH1 $PATH2 $PATH3 $PATH4; do
  for i in $(seq 1 10); do

    p=$path/msg00"${i}"

    n=`ls -lrt $p | wc -l`
 
    echo  " $p ==$n"
  done
done
That said, there are *much* better ways to do this.

Last edited by BMDan; 10-30-2008 at 03:34 PM.. Reason: Missing "$" in copied code.
  #3 (permalink)  
Old 10-30-2008
BMDan BMDan is offline
Registered User
  
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
For example (requires "find" with maxdepth option, and off the top of my head and untested, so no guarantees):

Code:
PATH1=/home/data1
PATH2=/home/data2
PATH3=/home/data3
PATH4=/home/data3 #should this be "data4"?

for toppath in $PATH1 $PATH2 $PATH3 $PATH4; do
  for subdir in $(find $toppath -maxdepth 1 -name 'msg00[0-9]'); do
    /bin/echo -n "$subdir: "
    find $subdir -type f | wc -l
  done
done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0