diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote
index 36593ef2..5942b2e3 100755
--- a/cdist/conf/type/__hostname/gencode-remote
+++ b/cdist/conf/type/__hostname/gencode-remote
@@ -55,18 +55,18 @@ fi
 ################################################################################
 # Setup hostname
 #
-echo 'changed' >> "$__messages_out"
+echo 'changed' >>"$__messages_out"
 
 
 # First try to set the hostname using hostnamectl, if available.
-if [ "$has_hostnamectl" ]; then
+if [ -n "$has_hostnamectl" ]; then
     # Allow hostnamectl to fail silently.
     # Who the fuck invented a tool that needs dbus to set the hostname anyway…
 
     # NOTE: We write the static hostname to /etc/hostname first in case
     #       hostnamectl fails. Fallback-code below will then adjust the running
     #       hostname below.
-    echo "printf '%s\\n' '$name_should' > /etc/hostname"
+    echo "echo '$name_should' >/etc/hostname"
 
     echo "hostnamectl set-hostname '$name_should' && exit 0"
 fi
@@ -75,7 +75,7 @@ fi
 case $os
 in
     alpine|archlinux|debian|devuan|ubuntu)
-        echo "printf '%s\\n' '$name_should' > /etc/hostname"
+        echo "echo '$name_should' >/etc/hostname"
         echo "hostname -F /etc/hostname"
     ;;
     coreos|openbmc-phosphor)
@@ -95,7 +95,7 @@ in
     suse)
         # We write into /etc/HOSTNAME for backwards-compatibility.  Modern SuSE
         # has hostnamectl anyway and symlinks /etc/HOSTNAME to /etc/hostname.
-        echo "printf '%s\\n' '$name_should' > /etc/HOSTNAME"
+        echo "echo '$name_should' >/etc/HOSTNAME"
         echo 'hostname -F /etc/HOSTNAME'
     ;;
     centos|fedora|freebsd|netbsd|openbsd|redhat|scientific)
diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest
index f3739f6c..a4068cc2 100755
--- a/cdist/conf/type/__hostname/manifest
+++ b/cdist/conf/type/__hostname/manifest
@@ -47,7 +47,7 @@ else
     esac
 fi
 
-if test -n "${max_len}" -a "$(printf "${name_should}" | wc -c)" -gt "${max_len}"
+if test -n "${max_len}" -a "$(printf '%s' "${name_should}" | wc -c)" -gt "${max_len}"
 then
 	printf "Host name too long. Up to %u characters allowed.\n" "${max_len}" >&2
 	exit 1