Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking a simple string condition 1

Status
Not open for further replies.

gringomike

Technical User
Aug 6, 2003
148
GB
Hi all,

Can anybody tell me why the script beloew does not work?


for file in `ls -1 /tmp/test`
do
if [ $file = string1.* ]
then
mv /tmp/test/$file /tmp/test/$file.ARCHIVE
else
mv /tmp/test/$file /tmp/test/$file.PROCESS
fi
done


It names every file in the directory *.PROCESS despite the presence of the "string1.12345" and "string198765" files.


Thanks in advance!

GM

 
Try something like this:
for file in `ls -1 /tmp/test`
do
case $file in
string1.*) mv /tmp/test/$file /tmp/test/$file.ARCHIVE;;
*) mv /tmp/test/$file /tmp/test/$file.PROCESS;;
esac
done


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top