[Discuss] Better way to detect sub files/dirs in BASH

pwillis p.willis at telus.net
Mon Mar 22 10:30:58 PDT 2010


Hello,


Does anyone have a simpler method to detect if
a directory or file is somewhere *below* a specified directory?


Currently I am doing somewhat like this:


#!/bin/bash

EXCLUDE_DIR="/some/excluded/dir"


for FILE in `cat file_list.txt`;do

  EXCL=`echo "${EXCLUDE_DIR}|${FILE}" | awk -F "|" '{I=index($2,$1);print I}'`
  if [ "$EXCL" == "1" ]; then
      echo "The file ${FILE}   is below ${EXCLUDE_DIR}."
  fi

done




Peter


More information about the Discuss mailing list