lundi 26 septembre 2016

If statement need to match multiple possibilities

I'm trying to make a smaal bash script to filter certain files from a few delevery folders of an FTP server, and when the files match a certain file naming convention it should pass.

I created a function to process the folders.

#!/bin/bash

function folder_search {
find FILE in `find ${DIR}/ -maxdepth 1 -type f -mmin +5 -name "*.doc" `; do
BASENAME=`basename $FILE`
if [[ $BASENAME == $NAMECONV1 or $BASENAME == $NAMECONV2 ]]
then
  "some commands"
else
  "some other commands
fi
}

#folder 1
DIR=/tmp/folder1
NAMECONV1="ABC[0-9][0-9][0-9].doc"
NAMECONV2="NL[0-9][0-9][0-9].doc"
folder_search

#folder 2
DIR=/tmp/folder2
NAMECONV1="ABC[0-9][0-9][0-9].doc"
NAMECONV2="B[0-9][0-9][0-9].doc"
folder_search

there are over 40 folders each with their own accepted nameing convention. so I need to have it dynamically in the IF statement by variables.

But I can't find the right set of [] {} '' "" () `` to get it working. Any help on this Or a completely different approach would help.

Thanks.

Aucun commentaire:

Enregistrer un commentaire