Robert Mark Bram
Robert Mark Bram

Reputation: 9683

Quoted string used in command

I thought I was quoting correctly, but I can't work out why I am getting these different results. Test directory:

ls /d/Temp/test

shows:

textFile.txt  textFile.txt.bak

And my test script is:

cd /d/Temp/test
excludeString="-not -iwholename '*.svn*' -not -iwholename '*.bak*'"
find -P . $excludeString -type f -name "*.*"
echo =======================
find -P . -not -iwholename '*.svn*' -not -iwholename '*.bak*' -type f -name "*.*"

and the results:

./textFile.txt
./textFile.txt.bak
=======================
./textFile.txt

Is this a quoting issue or something else?

Upvotes: 0

Views: 35

Answers (1)

that other guy
that other guy

Reputation: 123470

Bash doesn't interpret string data as code, since this is extremely unpredictable and leads to security vulnerabilities.

Shellcheck correctly suggests using an array instead:

excludeParams=(-not -iwholename '*.svn*' -not -iwholename '*.bak*')
find -P . "${excludeParams[@]}" -type f -name "*.*"

Upvotes: 2

Related Questions