Testing for member exists in shell script
Using the following to test existence of member in a directory
export MEMBER=HHO500 export TEMPDIR=/usr/temp if [ -e $TEMPDIR/$MEMBER.* ] then rm -f $TEMPDIR/MEMBER.* fi There could be a number of members in the TEMPDIR with the same MEMBER name. If a single entry then no probmem, but if several I get + '[' -e /usr/temp/HEO005.cbl /usr/temp/HEO005.dir /usr/temp/HEO005.idy ']' testjob1.sh: line 11: [: too many arguments This code was picked from our aix box which works fine. I did find a thread similar here and the suggestion was that the test condition worked differently under linux. any suggestions thanks first post so hope its gone to the correct forum |
hi,
may be you can count the items with ls HHO500 | wc -l then you can check the result if the number is bigger than your decide you can delete it. SM |
Quote:
Code:
rm -rf "$TEMPDIR/$MEMBER".* |
branch conditions
If you want delete every reference to that username than, as already suggested,
Code:
rm -rf "$TEMPDIR/$MEMBER".* If there is some special reason to distinguish between files and directories or links or permissions then extend your branch condition with any of these: Code:
-e File exists Regards, SIMP Fedora Development |
Thanks
Hey
Thanks for the prompt reply. I did in the end perform the rm -rf $TMPDIR/$MEMBER*.*. We had written this script to run on AIX as part of a porting piece, and the real reason for the Q was to check whether it was our coding or just difference between the OS. We will factor that in out scripts. Once again thanks for the reply |
Quote:
This should be safer: Code:
rm -r "${TEMPDIR?}/${MEMBER?}".* |
All times are GMT -5. The time now is 09:26 AM. |