Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a script which takes 3 arguments as input.

  1. path : where the files we want to check the ownership of are found.

  2. expected ownership : the expected ownership given as argument 2

  3. group : argument 3

There will be a whitelist file as well, which will have some of the file names. If any of the whitelisted file names are found, they should be skipped.

The script needs to print a message if any of the file's ownership doesn't match otherwise, it should print "all files have the expected ownership".

I tired the script but it's not working.. am not sure how to work with whitelist file logic.

Can someone please help me out.

#!/usr/bin/env bash


while IFS="" read -r matchedentry; do
    if [[ "$matchedentry" =~ $WHITELIST ]]; then
        echo -e "$matchedentry\r"
done < <(find "$PATH" -perm /u+w -user $Owner -o -perm /g+w -group $GROUP)

if (( $listcount > 0 )); then
        echo "$listcount items are having by '$Owner' ($whitelist_matches whitelisted)."
        echo "Files which are Not having correct ownership found ($whitelist_matches whitelisted)."
share|improve this question

As soon as you do this:


your script will no longer be able to locate the find program. Don't use $UPPER_CASE_VARS

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.