Background
What I'm trying to do is exclude all submodules of a git repository in a find command. I know that I can exclude a single directory like this:
find . -not -path './$submodule/*'
So I built a command that generates a lot of these statements and stores them:
EXCLUDES=$(for submodule in $(git submodule status | awk '{print $2}'); do
echo -n "-not -path './$submodule/*' ";
done)
Problem
But when I run find . $EXCLUDES, this does not work. I suspect this is because of a bash quoting strategy that I do not understand. For example, lets assume (# marks output):
tree .
# .
# ├── bar
# │ └── baz.scala
# └── foo.scala
set -x
EXCLUDES="-not -path './bar/*'"
find . -type f $EXCLUDES
# + find . -not -path ''\''./bar/*'\''' <---- weird stuff
# foo.scala
# baz.scala
find . -type f -not -path './bar/*'
# + find . -type f -not -path './bar/*'
# foo.scala
How do I tell bash not to to the weird quoting stuff its doing (see marked line above)?
Edit: @eddiem suggested using git ls-files, which I will do in this concrete case. But I'm still interested in how I'd do this in the general case where I have a variable with quotes and would like to use it as arguments to a command.
grepfor something in source files that are in your primary repo, but not in submodules? If so, you can accomplish that withgit grep.submoduleenv. variable in simple quotes. So it's not evaluated. Use no quotes or double quotes.git ls-files.