- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- While loop stuck
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 09:09 AM
07-15-2004 09:09 AM
Thanks
The REQFILE has
/RIP/module/resources/com/res/app/email/htmlConfirmationEmailHP.txt
RIP/module/resources/com/crm/client/UserMessages.properties
RIP/module/config/html/BrandDetectorServlet.properties
Script:
#!/bin/ksh
STAGEDIR=/home/user/Patch/build_patch/lists
SCRIPTDIR=/home/user/Patch
REQFILE=rip_files.txt
START=(What should I put)
END=`cat $REQFILE|wc -l`
echo $END
while [ $START -lt $END ]
do
for FLPATHNM in `cat $REQFILE`
do
cd $STAGEDIR
FSTCHR=`echo $FLPATHNM|awk '{print substr($0,1,1)}'`
LSTCHR=`echo $FLPATHNM|awk '{print substr($0,length($0),1)}'`
if [ $FSTCHR = "/" ]
then FLPATHNM1=`echo $FLPATHNM|awk '{print substr($0,2,length($0))}'`
else FLPATHNM1=`echo $FLPATHNM`
fi
if [ $LSTCHR = "/" ]
then TFLPATHNM2=`echo $FLPATHNM1|awk '{print substr($0,1,length($0)-1)}'`
else TFLPATHNM2=`echo $FLPATHNM1`
fi
TFLPATHNM4=`echo $TFLPATHNM2|sed 's/RIP\/module\/resources/temp\/RIP\/lib\/resourcepatches/'`
TFLPATHNM4=`echo $TFLPATHNM2|sed 's/RIP\/module\/config/temp\/RIP\/lib\/configpatches/'`
FLPATHNM2=$TFLPATHNM4
LENPATH=`echo $FLPATHNM2|awk '{print length()}'`
SLSHFLG=0
SLSHPOS=X
while [ $SLSHFLG -ne 1 ] && [ $LENPATH -gt 0 ]
do
CHRLKCMP=`echo $FLPATHNM2|awk '{print substr($0,'$LENPATH',1)}'`
if [ $CHRLKCMP = "/" ]
then SLSHFLG=1
SLSHPOS=$LENPATH
fi
((LENPATH = LENPATH - 1))
done
((SLSHPOS = SLSHPOS + 1))
CDPATH=`echo $FILENM|awk '{print substr($0,1,'$LENPATH')}'`
FILENM=`echo $FILENM|awk '{print substr($0,'$SLSHPOS',length())}'`
FSTCHR=`echo $FLPATHNM2|awk '{print substr($0,1,1)}'`
if [ $FSTCHR = "/" ]
then FILENM=`echo $FLPATHNM2|awk '{print substr($0,2)}'`
else FILENM=$FLPATHNM2
fi
LENPATH=`echo $FILENM|awk '{print length()}'`
SLSHFLG=0
SLSHPOS=X
while [ $SLSHFLG -ne 1 ] && [ $LENPATH -gt 0 ]
do
CHRLKCMP=`echo $FILENM|awk '{print substr($0,'$LENPATH',1)}'`
if [ $CHRLKCMP = "/" ]
then SLSHFLG=1
SLSHPOS=$LENPATH
fi
((LENPATH = LENPATH - 1))
done
if [ $SLSHPOS = X ]
then echo "ERROR: "$FILENM": Path Specified Is Incorrect!"
continue
fi
((SLSHPOS = SLSHPOS + 1))
cd /home/user/Patch
CDPATH=`echo $FILENM|awk '{print substr($0,1,'$LENPATH')}'`
echo $CDPATH
FILENM=`echo $FILENM|awk '{print substr($0,'$SLSHPOS',length())}'`
if [ -a $SCRIPTDIR/$CDPATH ]
then cd $SCRIPTDIR/$CDPATH
cp $MODULEDIR/$TFLPATHNM2 $SCRIPTDIR/$CDPATH
else mkdir -p $CDPATH
cp $MODULEDIR/$TFLPATHNM2 $SCRIPTDIR/$CDPATH
continue
fi
echo "-> File: "$FILENM
done
done(end while loop)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 09:29 AM
07-15-2004 09:29 AM
Re: While loop stuck
while read LINE
do
....
all your stuff
....
done < ${REQFILE}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 10:14 AM
07-15-2004 10:14 AM
Solutionwhile [ $START -lt $END ]
do
for FLPATHNM in `cat $REQFILE`
do
cd $STAGEDIR
.
.
.
done
done
the value of start and end never change. it is just like putting a while true do around your for loop. it doesn't do anything in this example. so the while start -lt end can be removed completely and the for loop is better written as the previous poster suggested. myself i like to see where my input is coming from at the begining of the while loop instead of the end, so I'd write it this way
cd $STAGEDIR
cat $REQFILE |
while read FLPATHNM
do
.
.
.
done
it is also more efficient to preform the cd only once instead of for everytime through the loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 10:40 AM
07-15-2004 10:40 AM
Re: While loop stuck
char2on=${FLPATHNM#?}
char1toNextToLast=${FLPATHNM%?}
fchar=${FLPATHNM%$char2on}
lchar=${FLPATHNM#$char1toNextToLast}
if [ $fchar = "/" ]
then FLPATHNM1=$char2on
else FLPATHNM1=$FLPATHNM
fi
if [ $lchar = "/" ]
then TFLPATHNM2=$char1toNextToLast
else TFLPATHNM2=$FLPATHNM1
fi
does the same thing as
FSTCHR=`echo $FLPATHNM|awk '{print substr($0,1,1)}'`
LSTCHR=`echo $FLPATHNM|awk '{print substr($0,length($0),1)}'`
if [ $FSTCHR = "/" ]
then FLPATHNM1=`echo $FLPATHNM|awk '{print substr($0,2,length($0))}'`
else FLPATHNM1=`echo $FLPATHNM`
fi
if [ $LSTCHR = "/" ]
then TFLPATHNM2=`echo $FLPATHNM1|awk '{print substr($0,1,length($0)-1)}'`
else TFLPATHNM2=`echo $FLPATHNM1`
fi
only about 5000 times faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 10:54 AM
07-15-2004 10:54 AM
Re: While loop stuck
for FLPATHNM in `cat $REQFILE`
I'm sure you are aware that you can't move your:
cd $STAGEDIR
outside the loop as you may or may not change directory later in your for loop and you do want to start at the right place the next time round I guess.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 11:34 AM
07-15-2004 11:34 AM
Re: While loop stuck
could be more readable as
TFLPATHNM4=`echo $TFLPATHNM2|sed 's!RIP/module/config!temp/RIP/lib/configpatches!'`
in sed the regular expression can be delimited by any character execpt a blank or a newline. So, if the pattern contains slashes, you could chosse another character, such as an exclamation mark as the delimiter.
and you can put both the subsitutions in the same command
TFLPATHNM4=`echo $TFLPATHNM2|sed -e 's!RIP/module/resources!temp/RIP/lib/resourcepatches!' -e 's!RIP/module/config!temp/RIP/lib/configpatches!'`
LENPATH=${#FLPATHNM2)
is much faster then
LENPATH=`echo $FLPATHNM2|awk '{print length()}'`
SLSHPOS=X
...
((SLSHPOS = SLSHPOS + 1))
....
FILENM=`echo $FILENM|awk '{print substr($0,'$SLSHPOS',length())}'`
I don't know how well using alphabetic characters are going to work when used in numeric contexts. I'd think you'd be better of using only digits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2004 12:23 PM
07-15-2004 12:23 PM
Re: While loop stuck
SLSHFLG=0
SLSHPOS=X
while [ $SLSHFLG -ne 1 ] && [ $LENPATH -gt 0 ]
do
CHRLKCMP=`echo $FLPATHNM2|awk '{print substr($0,'$LENPATH',1)}'`
if [ $CHRLKCMP = "/" ]
then SLSHFLG=1
SLSHPOS=$LENPATH
fi
((LENPATH = LENPATH - 1))
done
((SLSHPOS = SLSHPOS + 1))
CDPATH=`echo $FILENM|awk '{print substr($0,1,'$LENPATH')}'`
FILENM=`echo $FILENM|awk '{print substr($0,'$SLSHPOS',length())}'`
FSTCHR=`echo $FLPATHNM2|awk '{print substr($0,1,1)}'`
but your computing LENPATH and SLSHPOS using $FLPATHNM2 then applying it to FILENM
slshpos=${FLPATHNM2%/*}
slshpos=$((${#slshpos} + 1 ))
#lenpath=slshpos
echo $FILENM|awk -v slash=$slshpos '{
path=substr($0,1,slash);
file=substr($0,slash,length());
print path " " file;
}' | read cdpath filenm
does the same thing
and you already removed the leading slash once so it is redunant to do it again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2004 02:15 AM
07-16-2004 02:15 AM
Re: While loop stuck
Thanks Everyone
Thanks Again Mr Curt Larson