I'm simplifying a messy Bash script that synchronizes directories and their contents and files among several machines on a network using rsync.
The script gets file names, directory names, and glob patterns from a sources.txt
file with contents like (abridged):
go/
Pictures/
Videos/
Android/
.AndroidStudio*/
texmf/
.customization/
.local/share/rhythmbox/
.m2/
My smplified version of the updated script needs to expand globs within sources.txt
and present the result to rsync's --files-from=FILE
option. To do this, I'm using a helper script (expand-globs-in-file.sh
), reproduced below (and process substitution):
#!/bin/bash
if [ -n "$1" ]; then
cat $1 | tr '\n' '\0' | xargs -i -0 sh -c 'compgen -o bashdefault -G "{}"'
else
echo "Usage: $0 <filename>"
fi
What I am experiencing is that the script doesn't pass through some filenames (most begin with a period) while executing cat sources.txt | tr '\n' '\0' | xargs -i -0 sh -c 'compgen -o bashdefault -G "{}"'
on the command line works as expected.
Directory and file names/glob patterns that fail to be passed through:
.emacs
.gitconfig
.AndroidStudio*/
GPG-KEY-apacifico
network.txt
.jq
The following fle and directory names pass through correctly:
Documents/
Finances/
Downloads/
Development/
.android/
go/
Pictures/
Videos/
.cellphone/
Android/
texmf/
.customization/
.local/share/rhythmbox/
.m2/
useful-scripts/
rpmbuild/
texmf/
What am I doing wrong? I'm suspicious this is a quoting problem, but I don't see it.