The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-18-2007
xgringo xgringo is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
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 04:18 PM..
  #2 (permalink)  
Old 12-18-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #3 (permalink)  
Old 12-18-2007
xgringo xgringo is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
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?
  #4 (permalink)  
Old 12-18-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #5 (permalink)  
Old 12-18-2007
xgringo xgringo is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
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 ?
  #6 (permalink)  
Old 12-18-2007
porter porter is offline Forum Advisor  
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?
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 06:24 AM.


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