Skip to content

Commit d2379b2

Browse files
authored
chore(install): quote vars and defensive programming (ohmyzsh#13840)
1 parent ff1df9a commit d2379b2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

tools/install.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ USER=${USER:-$(id -u -n)}
5151
# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
5252
HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
5353
# macOS does not have getent, but this works even if $HOME is unset
54-
HOME="${HOME:-$(eval echo ~$USER)}"
54+
HOME="${HOME:-$(eval echo ~"$USER")}"
5555

5656

5757
# Track if $ZSH was provided
@@ -344,7 +344,7 @@ setup_zshrc() {
344344
return
345345
fi
346346

347-
if [ $OVERWRITE_CONFIRMATION != "no" ]; then
347+
if [ "$OVERWRITE_CONFIRMATION" != "no" ]; then
348348
# Ask user for confirmation before backing up and overwriting
349349
echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
350350
echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
@@ -475,12 +475,14 @@ EOF
475475
if user_can_sudo; then
476476
sudo -k >/dev/null 2>&1 || true # -k forces the password prompt when supported
477477
sudo chsh -s "$zsh" "$USER"
478+
chsh_status=$?
478479
else
479480
chsh -s "$zsh" "$USER" # run chsh normally
481+
chsh_status=$?
480482
fi
481483

482484
# Check if the shell change was successful
483-
if [ $? -ne 0 ]; then
485+
if [ "$chsh_status" -ne 0 ]; then
484486
fmt_error "chsh command unsuccessful. Change your default shell manually."
485487
else
486488
export SHELL="$zsh"

0 commit comments

Comments
 (0)