Where did my original .bash_profile go?

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.
pull/174/head
nickl- 2012-12-06 16:07:28 +02:00
parent 3ecc3a6038
commit d4d3d8c9e8
1 changed files with 6 additions and 0 deletions

View File

@ -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"