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
Getting yesterday DATE osymad Shell Programming and Scripting 16 06-06-2008 05:46 AM
Yesterday in i.e. May 09 and 05/09 format Daniel Gate Shell Programming and Scripting 3 05-20-2008 01:59 PM
yesterday Tlg13team Shell Programming and Scripting 0 02-27-2008 12:02 AM
How to show yesterday date wind_n_cloud Shell Programming and Scripting 1 02-16-2005 06:51 PM
minor issue on question that i had posted !! moxxx68 Post Here to Contact Site Administrators and Moderators 4 10-23-2004 01:51 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-18-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Cool Posted a Question Yesterday

Was wondering if it was too stupid and got deleted? Because it's gone now from the board.

I was asking about For Loops ----?


#!/usr/bin/bash

bank=`cat /export/home/usr/banklist.txt`
cdir=`cat /export/home/usr/mountlist.txt`
for d in $cdir
do
ls -l /apps/data/custdata/$d/$i/incoming/
ls -l /apps/data/custdata/$d/$i/outgoing/

for d in $bank
do

ls -l /apps/data/custdata/$d/$i/incoming/
ls -l /apps/data/custdata/$d/$i/outgoing/
done;
done;

The question was asking how to fill in the variables from two different lists of files and when they match peform an action ls -ltr for example?

If this gets deleted it must mean I need to go to the Unix for dummies thread?

Last edited by xgringo; 12-18-2007 at 12:18 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-18-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
Sorry. We had a technical problem yesterday and lost the database. We restored a backup, but we lost a couple of hours of posts.

I don't understand your question, but you show two "for" loops, one nested inside the other. No problem there. But both are using the same variable d. The inner loop needs its own variable.
Reply With Quote
  #3 (permalink)  
Old 12-18-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Ok well not sure I have one list say

lisa a

1
2
3
4

list b

d
e
f
g

So I need something like if $a and $b exist at the same time, then do

ls -l /apps/data/custdata/$a/$b/incoming/
ls -l /apps/data/custdata/$a/$b/outgoing/

The problem being soemtimes there will be an /apps/data/custdata/1/d/incoming/ directory but there will be also times when an /apps/data/custdata/3/f/incoming/ won't exist --- I want to do an ls on the two combos from the two different list files that match?
Reply With Quote
  #4 (permalink)  
Old 12-18-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
Try something like:

Code:
for a in 1 2 3 4 ; do
   for b in d e f g ; do
       if [[ -d /apps/data/custdata/$a/$b/incoming/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/incoming/
       fi
       if [[ -d /apps/data/custdata/$a/$b/outgoing/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/outgoing/
       fi
   done
done
That -d is just testing to see if a directory exists with that path.
Reply With Quote
  #5 (permalink)  
Old 12-18-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Quote:
Originally Posted by Perderabo View Post
Try something like:

Code:
for a in 1 2 3 4 ; do
   for b in d e f g ; do
       if [[ -d /apps/data/custdata/$a/$b/incoming/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/incoming/
       fi
       if [[ -d /apps/data/custdata/$a/$b/outgoing/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/outgoing/
       fi
   done
done
That -d is just testing to see if a directory exists with that path.
I got zero out put when I ran the script so I did set -xv

and I got data like this

+ [[ -d /apps/data/custdata/tmp2/noma/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/lima/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/urma/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/filoma/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/triloma/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/cbass/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/estate/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/fondu/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/kingson/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/lupra/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/jag/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/tyson/incoming

So it looks like it passed the if statement but doesn't get a + for the ls ?
Reply With Quote
  #6 (permalink)  
Old 12-18-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by xgringo View Post
So it looks like it passed the if statement but doesn't get a + for the ls ?
Do those directories, as listed, exist?
Reply With Quote
  #7 (permalink)  
Old 12-18-2007
Registered User
 

Join Date: Dec 2006
Posts: 28
Yes they do exist so they exist but I don't get an ls of them.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:20 PM.


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

Content Relevant URLs by vBSEO 3.2.0