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.

4

1 回答 1

0

不完全确定为什么,但将输入参数分成自己的字符串似乎可行。在这里,它作为一个工作的 shell 函数和大小写不变量。


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



于 2020-05-12T08:44:42.750 回答