summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2022-03-07 11:38:48 +0100
committerMarc Cornellà <hello@mcornella.com>2022-03-07 11:41:02 +0100
commit4f0b680248e1acf71e9e557af62f3a08bb5b96c6 (patch)
tree980ade0541571026b03544ef59297c8d2c6d898e /tools
parent9350e1ff8724341534a8def2ce76ede88a4c2868 (diff)
downloadzsh-4f0b680248e1acf71e9e557af62f3a08bb5b96c6.tar.gz
zsh-4f0b680248e1acf71e9e557af62f3a08bb5b96c6.tar.bz2
zsh-4f0b680248e1acf71e9e557af62f3a08bb5b96c6.zip
fix(installer): fix `$HOME` setting if `getent` is not found (macOS)
Related: https://github.com/ohmyzsh/ohmyzsh/pull/10713/files#r820219899
Diffstat (limited to 'tools')
-rwxr-xr-xtools/install.sh4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/install.sh b/tools/install.sh
index 93608eb7c..f04d0dc9c 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -45,7 +45,9 @@ USER=${USER:-$(id -u -n)}
# $HOME is defined at the time of login, but it could be unset. If it is unset,
# a tilde by itself (~) will not be expanded to the current user's home directory.
# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
-HOME="${HOME:-$(getent passwd $USER | cut -d: -f6)}"
+HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
+# macOS does not have getent, but this works even if $HOME is unset
+HOME="${HOME:-$(eval echo ~$USER)}"
# Track if $ZSH was provided