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?
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.
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?
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.
It's not irrelevant, just different. The test says "is the following entry a directory?" Putting a trailing slash says "Don't match unless this is a directory" it's redundant.
It starts to become extremely important to know the difference when you use mv, if you include a trailing / on the desitnation path, it will fail if the dir does not exist. If you leave it off, it will rename the source to the name of the desitnation directory but only if it doesn't exist
if [[ -d /apps/data/custdata/$d/$i/incoming ]] ; then
ls -ltra /apps/data/custdata/$d/$i/incoming
fi
if [[ -d /apps/data/custdata/$d/$i/outgoing ]] ; then
ls -ltra /apps/data/custdata/$d/$i/outgoing
fi
if test -d /apps/data/custdata/$d/$i/incoming ; then
ls -ltra /apps/data/custdata/$d/$i/incoming
fi
if test -d /apps/data/custdata/$d/$i/outgoing ; then
ls -ltra /apps/data/custdata/$d/$i/outgoing
fi