0

In bash, I have a directory that holds some file names that start with underscore _ and others that don't.

I want my script to check if a folder has any files that don't start with _. I write

if [[ -f $dir/[!_]* ]]
  then echo "There are unmarked files."
  else echo "All files marked."
fi 

But when I run using a folder with files that do and do not start with _, the if statement has the opposite effect of what I intended. I list the entries in the folder that clearly display files without _, but the output keeps saying, All files marked.

What am I missing?

0
if find -not -name '_*' -exec false {} +
then
  echo 'all files marked'
else
  echo 'unmarked file found'
fi
| improve this answer | |
  • @muru {} ';' is not the same as {} + - perhaps you could perform an apples for apples test before commenting further - thanks – Steven Penny Feb 16 '18 at 16:31

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