Generate a find command with pruned directories based on a config file The idea is to perform indexing of filetrees while excluding certain directories. I want to give the user a simple conf file instead of having to edit the script itself.
This is what I came up with:
conf.file:
cache
home/files

program:
#!/usr/bin/env bash

function get_opts {
        while read opt
        do
        echo &quot;-path /data/data/com.termux/$opt -prune -o \\&quot; &gt;&gt; fn_temp
        done &lt; conf.file
}

function build_search_fn {
        touch fn_temp
        echo &quot;function do_search {&quot; &gt; fn_temp
        echo &quot;find /data/data/com.termux \\&quot; &gt;&gt; fn_temp
        get_opts
        echo &quot;-print&quot; &gt;&gt; fn_temp
        echo &quot;}&quot; &gt;&gt; fn_temp
}

build_search_fn
source fn_temp
do_search &gt;&gt; output

It does what I want, but I have a strong feeling that it's not the 'proper' way of doing it. Besides the obvious lack of putting the base path into variables and some errorhandling I'm eager to learn about other approaches to do this.
You can use subcommands in a command:
echo &quot;This $(date) is a date calculated in the echo command&quot;

When you don't need additional control statements, you can use combined code like:
find /data/data/com.termux \
   $(awk '{printf(&quot;-path %s%s -prune -o &quot;, &quot;/data/data/com.termux/&quot;, $0)}' conf.file) \
   -print &gt;&gt; output

The awk command might be new for you, it is a replacement for your loop over the conf file. The same result can be found with sed:
sed 's#.*#/data/data/com.termux/&amp; -prune -o #' conf.file

I think awk is the best here.