From d4d3d8c9e8bb4901bc5b09cb5813e87b115fbf17 Mon Sep 17 00:00:00 2001 From: nickl- Date: Thu, 6 Dec 2012 16:07:28 +0200 Subject: [PATCH] Where did my original .bash_profile go? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's nice that we make a backup but… * what if a back-up already exists? * what if this is the 2nd, 3rd or 4th time I'm executing the script? We backup to .bash_profile.bak or .bash_plofile.bak.{count} if .bash_plofile.bak already exists. iow .bash_plofile.bak if not exist .bash_plofile.bak.1 if exists .bash_plofile.bak.2 if 2 exists .bash_plofile.bak.3 if 3 exists etc… Newest backup with the highest number. --- install.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/install.sh b/install.sh index 4630b211..4a09e22b 100755 --- a/install.sh +++ b/install.sh @@ -3,6 +3,12 @@ BASH_IT=$(cd ${0%/*} && echo ${PWD}) cd "${OLDPWD}" cp "${HOME}/.bash_profile" "${HOME}/.bash_profile.bak" +BASH_PROFILE_BAK="${HOME}/.bash_profile.bak" +if [ -f "${BASH_PROFILE_BAK}" ]; then + list=($(ls "${BASH_PROFILE_BAK}"*)) + BASH_PROFILE_BAK="${BASH_PROFILE_BAK}.${#list[@]}" +fi + echo "Your original .bash_profile has been backed up to .bash_profile.bak" cp "${BASH_IT}/template/bash_profile.template.bash" "${HOME}/.bash_profile"