I'm trying to write a dotfiles installer/initializer script that works in the newer MacOS zsh and I'm having trouble. Here's my script:
#!/bin/sh
BACKUP_DIR="~/.backup"
echo "Checking $BACKUP_DIR directory (This check is broken on zsh but should work on bash)"
while [ -d "$BACKUP_DIR" ]
do
BACKUP_DIR="$BACKUP_DIR_$RANDOM"
echo "the backup folder already exists trying $BACKUP_DIR instead"
done
echo "backing up existing dot files."
for each in `ls -lad \.* | grep ^- | rev | cut -w -f 1 | rev`
do
mv ~/$each $BACKUP_DIR/$each
done
here's what I get when I run it:
cliftoncraig@Cliftons-MBP .dotfiles % ./install
Checking ~/.backup directory (This check is broken on zsh but should work on bash)
backing up existing dot files.
mv: rename /Users/cliftoncraig/.gitconfig to ~/.backup/.gitconfig: No such file or directory
mv: rename /Users/cliftoncraig/.zprofile to ~/.backup/.zprofile: No such file or directory
cliftoncraig@Cliftons-MBP .dotfiles % ls ~/.gitconfig
/Users/cliftoncraig/.gitconfig
As you can see, when I validate that the files it's trying to backup actually exist it leaves me puzzled. What am I doing wrong?