![]() |
|
|
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 |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
Last edited by BMDan; 10-30-2008 at 03:34 PM.. Reason: Missing "$" in copied code. |
|
||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|