I'm working on a deploy script for my dotfiles, they are stored on a Git bare repository, from which i
git checkout it's files into my home directory, in order to seamlessy do it without thousands of Git checkout errors, i must remove the already existing ones (
.bashrc for instance), i'm actually retrieving them with the following command
git --git-dir=$HOME/repos/dots --work-tree=$HOME ls-tree --full-tree --full-name --name-only -r HEAD | sed "s|^|/mnt/home/henriquehbr/|"
Note: the reason for
/mntis that it is the mountpoint for my chrooted installation, i'm actually running it from my custom Arch Linux installation image
But when it comes to actually removing these files, i had no success, the problem lies on the ones that contains spaces in their names (
Font\ Awesome\ Icons.otf for instance)
I've tried quoting every single file to be removed by piping the command above on the following sequence of commands:
<get_dotfiles> | sed "s|^|\"/mnt/home/henriquehbr/|" | sed "s/$/\"/"
The method above didn't worked, i think
rm was treating the quotes literally, as if they were part of the filename
Other trial was by making a good ol'
dotfiles=$(git --git-dir=$HOME/repos/dots --work-tree=$HOME ls-tree --full-tree --full-name --name-only -r HEAD | sed "s|^|/mnt/home/henriquehbr/|") for dotfile in $dotfiles; do echo "$dotfile" # Works properly, displays dotfile path rm "$dotfile" # Doesn't works, writes: '$'\n'' after the path and fails done