Subject: [bug#77035] [PATCH v3 4/5] system & home: profile: Address issues reported by ‘shellcheck’.

From: Hilton Chain <[email-masked]>
Date: Tue, 1 Apr 2025 23:02:47 +0800

* gnu/system.scm (operating-system-etc-service)[profile]: Address issues
reported by ‘shellcheck’.
* gnu/home/services.scm (environment-variables->setup-environment-script):
Likewise.
* gnu/home/services/shells.scm (add-shell-profile-file): Likewise.

Change-Id: I4e230fd239b8a8450da6ee0c2e58746c9cc38785
---
 gnu/home/services.scm        | 16 ++++++++++------
 gnu/home/services/shells.scm |  4 ++--
 gnu/system.scm               | 10 +++++-----
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 6be1a49a90..769bc1c033 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -287,27 +287,31 @@ (define (environment-variables->setup-environment-script vars)
 
 case $GUIX_LOCPATH in
   *$GUIX_PROFILE/lib/locale*) ;;
-  *) export GUIX_LOCPATH=$GUIX_PROFILE/lib/locale:$GUIX_LOCPATH ;;
+  *) export GUIX_LOCPATH=\"$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH\" ;;
 esac
 case $XDG_DATA_DIRS in
   *$GUIX_PROFILE/share*) ;;
-  *) export XDG_DATA_DIRS=$GUIX_PROFILE/share:$XDG_DATA_DIRS ;;
+  *) export XDG_DATA_DIRS=\"$GUIX_PROFILE/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS\" ;;
 esac
+# When MANPATH is unset, add a trailing colon so the system default search path
+# is used.
 case $MANPATH in
   *$GUIX_PROFILE/share/man*) ;;
-  *) export MANPATH=$GUIX_PROFILE/share/man:$MANPATH
+  *) export MANPATH=\"$GUIX_PROFILE/share/man:$MANPATH\" ;;
 esac
+# When INFOPATH is unset, add a trailing colon so Emacs searches
+# 'Info-default-directory-list'.
 case $INFOPATH in
   *$GUIX_PROFILE/share/info*) ;;
-  *) export INFOPATH=$GUIX_PROFILE/share/info:$INFOPATH ;;
+  *) export INFOPATH=\"$GUIX_PROFILE/share/info:$INFOPATH\" ;;
 esac
 case $XDG_CONFIG_DIRS in
   *$GUIX_PROFILE/etc/xdg*) ;;
-  *) export XDG_CONFIG_DIRS=$GUIX_PROFILE/etc/xdg:$XDG_CONFIG_DIRS ;;
+  *) export XDG_CONFIG_DIRS=\"$GUIX_PROFILE/etc/xdg${XDG_CONFIG_DIRS:+:}$XDG_CONFIG_DIRS\" ;;
 esac
 case $XCURSOR_PATH in
   *$GUIX_PROFILE/share/icons*) ;;
-  *) export XCURSOR_PATH=$GUIX_PROFILE/share/icons:$XCURSOR_PATH ;;
+  *) export XCURSOR_PATH=\"$GUIX_PROFILE/share/icons${XCURSOR_PATH:+:}$XCURSOR_PATH\" ;;
 esac
 
 # Keep the shell environment clean.
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index 35c0c52a8e..97c9331e18 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -87,13 +87,13 @@ (define (add-shell-profile-file config)
      ,(mixed-text-file
        "shell-profile"
        "\
-HOME_ENVIRONMENT=$HOME/.guix-home
+HOME_ENVIRONMENT=\"$HOME/.guix-home\"
 # Skip if already sourced.
 case $INFOPATH in
   *$HOME_ENVIRONMENT/profile/share/info*) ;;
   *) . \"$HOME_ENVIRONMENT/setup-environment\" ;;
 esac
-$HOME_ENVIRONMENT/on-first-login
+\"$HOME_ENVIRONMENT/on-first-login\"
 unset HOME_ENVIRONMENT\n"
        (serialize-configuration
         config
diff --git a/gnu/system.scm b/gnu/system.scm
index 71464bb712..bbf2f2afd3 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -1071,11 +1071,11 @@ (define* (operating-system-etc-service os)
 # loaded when someone logs in via SSH.  See <http://bugs.gnu.org/22175>.
 # We need 'PATH' to be defined here, for 'cat' and 'cut'.  Do this before
 # reading the user's 'etc/profile' to allow variables to be overridden.
-if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\
-     -a -z \"$LINUX_MODULE_DIRECTORY\" ]
+if [ -f /etc/environment ] && [ -n \"$SSH_CLIENT\" ] &&
+     [ -z \"$LINUX_MODULE_DIRECTORY\" ]
 then
   . /etc/environment
-  export `/run/current-system/profile/bin/cut -d= -f1 < /etc/environment`
+  export \"$(/run/current-system/profile/bin/cut -d= -f1 < /etc/environment)\"
 fi
 
 # Set up environment for all default profiles.
@@ -1152,10 +1152,10 @@ (define* (operating-system-etc-service os)
 unset HOME_ENVIRONMENT
 
 # Prepend paths not in a profile.
-export PATH=/run/privileged/bin:$PATH
+export PATH=\"/run/privileged/bin:$PATH\"
 export XCURSOR_PATH=\"$HOME/.icons:$XCURSOR_PATH\"
 
-if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
+if [ -n \"$BASH_VERSION\" ] && [ -f /etc/bashrc ]
 then
   # Load Bash-specific initialization code.
   . /etc/bashrc
-- 
2.49.0