Article 5C70Y How to Use a Variable with the Find Command

How to Use a Variable with the Find Command

by
Steve R.
from LinuxQuestions.org on (#5C70Y)
I have a homemade backup program where I use the find command to send the files to be backed-up to tar. The find command below works as expected with the filenames hard-coded.
Code:search_directory="/home/steve"
find $search_directory ! -path "${search_directory}/\.*" ! -path "${search_directory}/X\-Plane_11*" ! -path "${search_directory}/Torrent_Files*" > test_find.txtWhat I would like to do is have the search criteria use a variable (exclude_string) to exclude files that do not have to be backed-up. However, that is not working.
Code:exclude_string=' ! -path "${search_directory}/\.*" ! -path "${search_directory}/X\-Plane_11*" ! -path "${search_directory}/Torrent_Files*"'
find $search_directory ${exclude_string} > test_find.txtWhen run, no error is displayed. The find command simply shows all files as if the variable exclude_string did not exist.latest?d=yIl2AUoC8zA latest?i=YNVF_dxp8Jo:OJNBw0IVs_0:F7zBnMy latest?i=YNVF_dxp8Jo:OJNBw0IVs_0:V_sGLiP latest?d=qj6IDK7rITs latest?i=YNVF_dxp8Jo:OJNBw0IVs_0:gIN9vFwYNVF_dxp8Jo
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments