From 0b3b8e4b89cd272fd84bce442345c0bbc2c601e8 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Sat, 6 Feb 2016 10:50:13 +0100 Subject: Handle missing configuration file gracefully --- python.eselect.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python.eselect.in b/python.eselect.in index e05bff1..0945c63 100644 --- a/python.eselect.in +++ b/python.eselect.in @@ -32,6 +32,8 @@ get_installed_pythons() { # includes both preferred implementations (in preference order) # and disabled interpreters. get_all_preferences() { + [[ -e ${CONFIG_PATH} ]] || return + local l while read l; do # skip comments @@ -98,7 +100,10 @@ get_all_pythons() { # Write new preference list. Preferences need to be passed # as parameters (${@}). write_preferences() { - sed -n -e '/^#/p' "${CONFIG_PATH}" > "${CONFIG_PATH}".new || die + if [[ -e ${CONFIG_PATH} ]]; then + sed -n -e '/^#/p' "${CONFIG_PATH}" > "${CONFIG_PATH}".new || die + fi + local IFS=$'\n' echo "${*}" >> "${CONFIG_PATH}".new || die -- cgit v1.2.3-65-gdbad