The basic code is:
Code: Select all
echo_items(){
for item in "${code_to_include}" "${directories_to_include}"; do
if [ -d "$item" ]; then
find . -wholename "./$item"'/*'
else
echo "./$item"
fi
done
}
echo_items | tar -czvf "$output_name" --files-from -
And the above link is an example of how one might use it. I could make this code more robust by adding the " -print0" option to the above find statment, in which case one would need to add the "--null" option to tar.
See:
https://stackoverflow.com/questions/259 ... from-stdin
but I would probably need to do a few more changes to the above code for this to work.
Note that when I tried this it says that tar exited with an error but the code seems to work and the archive looks like it was created. Perhaps this is due to some strange file I have in one of my directories (or maybe I need to repair my file system).
Edit 1
Actually, I'm surprised this worked because I would think that an ampersand is missing and the above line should be:
Code: Select all
for item in "${code_to_include[@]}" "${directories_to_include[@]}"; do