From 19fe69e5666010d5055126db4f7561fe8cdc8234 Mon Sep 17 00:00:00 2001 From: nickl- Date: Thu, 6 Dec 2012 16:11:06 +0200 Subject: [PATCH] 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. --- install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4a09e22b..e6376a88 100755 --- a/install.sh +++ b/install.sh @@ -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"