What if .bash_profile doesn't exist?

We get an error from cp
We still respond that we made a backup
Instead if .bas_profile exists and cp is a success then prompt informing the user that we made a backup
or inform them that no .bash_profile was found so no need to make a back up at this point.
pull/174/head
nickl- 2012-12-06 16:11:06 +02:00
parent d4d3d8c9e8
commit 19fe69e566
1 changed files with 5 additions and 1 deletions

View File

@ -3,13 +3,17 @@
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"
[[ -f "${HOME}/.bash_profile" ]] \
&& cp "${HOME}/.bash_profile" "${BASH_PROFILE_BAK}" \
&& echo "Your original .bash_profile has been backed up to ${BASH_PROFILE_BAK##*/}" \
|| echo "No original .bash_profile file found so we have nothing to back up"
cp "${BASH_IT}/template/bash_profile.template.bash" "${HOME}/.bash_profile"