0

Mac OSX Bash Shell

I want to use find to identify anything (directories or files) which do not follow an input pattern.

This works fine:

find . -path /Users/Me/Library -prune -o \! \( -path '*.jpg' \)

However I want to have a general ability to do from a bash alias or function eg:

alias negate_find="find . -path /Users/Me/Library -prune -o \! \( -path ' "$1" ' \)"

To allow shell input of the search term (which may contain spaces). The current syntax does not work, returning unknown primary or operator on invocation. Grateful for assistance in what I am doing wrong.

Richard L
  • 85
  • 6

1 Answers1

0

Not entirely sure why, but separating the input parameter into its own string seemed to work. Here it is as a working shell function and case invariant.


negate_find () {
search="$1"
lowersearch=$(echo "$search" | awk '{print tolower($0)}')
uppersearch=$(echo "$search" | awk '{print toupper($0)}')
echo "search = $search"
find . -path $HOME/Library -prune -o \! \(  -path "$lowersearch"  \)  -a \! \(  -path "$uppersearch"  \)
}
export -f negate_find



Richard L
  • 85
  • 6