diff --git a/cdist/conf/type/__cron/gencode-remote b/cdist/conf/type/__cron/gencode-remote
index f58896af..ee626485 100755
--- a/cdist/conf/type/__cron/gencode-remote
+++ b/cdist/conf/type/__cron/gencode-remote
@@ -58,7 +58,7 @@ state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
 # These are the old markers
 prefix="#cdist:__cron/$__object_id"
 suffix="#/cdist:__cron/$__object_id"
-filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V|^# \(Cronie version .\..\)$"
+filter="^# DO NOT EDIT THIS FILE|^# \\(.* installed on |^# \\(Cron version V|^# \\(Cronie version .\\..\\)$"
 cat << DONE
 crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
 {
diff --git a/cdist/conf/type/__install_coreos/gencode-remote b/cdist/conf/type/__install_coreos/gencode-remote
index fbe86479..f550b5a5 100755
--- a/cdist/conf/type/__install_coreos/gencode-remote
+++ b/cdist/conf/type/__install_coreos/gencode-remote
@@ -12,7 +12,7 @@ eof
 
 coreos-install -d "${device}" \
 	\$(if [ -s "\${ignition_file}" ]; then
-		printf -- "-i \${ignition_file}\n"
+		printf -- "-i \${ignition_file}\\n"
 	fi)
 
 rm "\${ignition_file}"
diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote
index 947dd472..ac9ae6cf 100755
--- a/cdist/conf/type/__install_reset_disk/gencode-remote
+++ b/cdist/conf/type/__install_reset_disk/gencode-remote
@@ -67,5 +67,5 @@ fi
 
 # erase partition table
 dd if=/dev/zero of=$disk bs=512 count=1
-printf 'w\n' | fdisk -u -c $disk || true
+printf 'w\\n' | fdisk -u -c $disk || true
 DONE
diff --git a/cdist/conf/type/__jail_freebsd10/gencode-remote b/cdist/conf/type/__jail_freebsd10/gencode-remote
index 230370c2..a5e097f9 100755
--- a/cdist/conf/type/__jail_freebsd10/gencode-remote
+++ b/cdist/conf/type/__jail_freebsd10/gencode-remote
@@ -45,7 +45,7 @@ else
 #    when $state=present, it's required. Enforce this.
    if [ "$state" = "present" ]; then
       exec >&2
-      echo "If --state is 'present,' --ip must be given\!"
+      echo "If --state is 'present,' --ip must be given\\!"
       exit 1
    fi
 fi
@@ -114,17 +114,17 @@ startJail() {
 deleteJail() {
 # Unmount the jail's mountpoints if necessary
    cat <<EOF
-      output="\$(mount | grep "\/${name}\/dev")" || true
+      output="\$(mount | grep "\\/${name}\\/dev")" || true
       if [ -n "\${output}" ]; then # /dev is still mounted...jail still running?
          /etc/rc.d/jail stop "${name}"
       fi
-      output="\$(mount | grep "\/rw\/${name}\/")" || true
+      output="\$(mount | grep "\\/rw\\/${name}\\/")" || true
       if [ -n "\${output}" ]; then # >=1 rw mount is mounted still
          for DIR in "${output}"; do
             umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print \$3}')"
          done
       fi
-      output="\$(mount | grep "\/${name} (")" || true
+      output="\$(mount | grep "\\/${name} (")" || true
       if [ -n "\${output}" ]; then # ro mount is mounted still
          umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print \$3}')"
       fi
@@ -275,9 +275,9 @@ cat <<EOF
       if [ ! -f /etc/devfs.rules ]; then
          touch /etc/devfs.rules
       fi
-      if [ -z "\$(grep '\[jailrules=' /etc/devfs.rules)" ]; then   # The default ruleset doesn't exist
+      if [ -z "\$(grep '\\[jailrules=' /etc/devfs.rules)" ]; then   # The default ruleset doesn't exist
          # Get the highest-numbered ruleset
-         highest="\$(sed -n 's/\[.*=\([0-9]*\)\]/\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true
+         highest="\$(sed -n 's/\\[.*=\\([0-9]*\\)\\]/\\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true
          # increment by 1
          [ -z "\$highest" ] && highest=10
          let num="\${highest}+1" 2>&1 >/dev/null   # Close the FD==fail...
@@ -290,7 +290,7 @@ add include \\\$devfsrules_unhide_basic
 add include \\\$devfsrules_unhide_login
 END
       fi
-      devfsruleset_num=\$(grep "\[${devfsruleset}=" /etc/devfs.rules | sed -n 's/\[.*=\([0-9]*\)\]/\1/pg')
+      devfsruleset_num=\$(grep "\\[${devfsruleset}=" /etc/devfs.rules | sed -n 's/\\[.*=\\([0-9]*\\)\\]/\\1/pg')
       if [ -n "\$devfsruleset_num" ]; then
          jaildata="\$jaildata
          devfs_ruleset=\"\${devfsruleset_num}\";"
@@ -299,7 +299,7 @@ END
 
 EOF
    # shellcheck disable=SC2028
-   echo "printf \"%s\\n%s\n%s\n\" \"\$jailheader\" \"\$jaildata\" \"\$jailtrailer\" >>\"\$jailfile\""
+   echo "printf \"%s\\n%s\\n%s\\n\" \"\$jailheader\" \"\$jaildata\" \"\$jailtrailer\" >>\"\$jailfile\""
 
 # Add $name to jail_list if $onboot=yes
 if [ "$onboot" = "yes" ]; then
diff --git a/cdist/conf/type/__jail_freebsd9/gencode-remote b/cdist/conf/type/__jail_freebsd9/gencode-remote
index 13c237a9..7f3828b2 100755
--- a/cdist/conf/type/__jail_freebsd9/gencode-remote
+++ b/cdist/conf/type/__jail_freebsd9/gencode-remote
@@ -45,7 +45,7 @@ else
 #    when $state=present, it's required. Enforce this.
    if [ "$state" = "present" ]; then
       exec >&2
-      echo "If --state is 'present,' --ip must be given\!"
+      echo "If --state is 'present,' --ip must be given\\!"
       exit 1
    fi
 fi
@@ -119,17 +119,17 @@ startJail() {
 deleteJail() {
 # Unmount the jail's mountpoints if necessary
    cat <<EOF
-      output="\$(mount | grep "\/${name}\/dev")" || true
+      output="\$(mount | grep "\\/${name}\\/dev")" || true
       if [ -n "\${output}" ]; then # /dev is still mounted...jail still running?
          /etc/rc.d/jail stop "${name}"
       fi
-      output="\$(mount | grep "\/rw\/${name}\/")" || true
+      output="\$(mount | grep "\\/rw\\/${name}\\/")" || true
       if [ -n "\${output}" ]; then # >=1 rw mount is mounted still
          for DIR in "${output}"; do
             umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print \$3}')"
          done
       fi
-      output="\$(mount | grep "\/${name} (")" || true
+      output="\$(mount | grep "\\/${name} (")" || true
       if [ -n "\${output}" ]; then # ro mount is mounted still
          umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print \$3}')"
       fi
@@ -279,9 +279,9 @@ END
       if [ ! -f /etc/devfs.rules ]; then
          touch /etc/devfs.rules
       fi
-      if [ -z "\$(grep '\[jailrules=' /etc/devfs.rules)" ]; then   # The default ruleset doesn't exist
+      if [ -z "\$(grep '\\[jailrules=' /etc/devfs.rules)" ]; then   # The default ruleset doesn't exist
          # Get the highest-numbered ruleset
-	 highest="\$(sed -n 's/\[.*=\([0-9]*\)\]/\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true
+	 highest="\$(sed -n 's/\\[.*=\\([0-9]*\\)\\]/\\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true
          # increment by 1
          let num="\${highest}+1" 2>&- >&-
          # add default ruleset
diff --git a/cdist/conf/type/__mount/gencode-remote b/cdist/conf/type/__mount/gencode-remote
index 66d85f88..e8266a0b 100755
--- a/cdist/conf/type/__mount/gencode-remote
+++ b/cdist/conf/type/__mount/gencode-remote
@@ -39,7 +39,7 @@ case "$state_should" in
             printf ' -o %s' "$(cat "$__object/parameter/options")"
          fi
          printf ' %s' "$(cat "$__object/parameter/device")"
-         printf " %s\n" "$path"
+         printf " %s\\n" "$path"
       else
          # mount using existing fstab entry
          printf 'mount "%s"\n' "$path"
diff --git a/cdist/conf/type/__package_pkgng_freebsd/gencode-remote b/cdist/conf/type/__package_pkgng_freebsd/gencode-remote
index b59e3648..592d4d0f 100755
--- a/cdist/conf/type/__package_pkgng_freebsd/gencode-remote
+++ b/cdist/conf/type/__package_pkgng_freebsd/gencode-remote
@@ -95,7 +95,7 @@ if [ -n "$curr_version" ]; then  # PKG *is* installed
       if [ "$upgrade" = "true" ]; then
          execcmd "upg" "${cmd}"
       else
-         printf "Version %s is already installed and pkg-ng can't upgrade directly to version %s.\nTo upgrade to the latest version, use the --upgrade flag.\n" "$curr_version" "$version" >&2
+         printf "Version %s is already installed and pkg-ng can't upgrade directly to version %s.\\nTo upgrade to the latest version, use the --upgrade flag.\\n" "$curr_version" "$version" >&2
          exit 1
       fi
    # PKG is supposed to be installed to the latest version
diff --git a/cdist/conf/type/__rvm/gencode-remote b/cdist/conf/type/__rvm/gencode-remote
index 494c8fd8..993191c1 100755
--- a/cdist/conf/type/__rvm/gencode-remote
+++ b/cdist/conf/type/__rvm/gencode-remote
@@ -34,7 +34,7 @@ DONE
     absent)
         cat << DONE
 su - $user -c "rm -Rf \"\\\$HOME/.rvm\";
-sed '/rvm\/scripts\/rvm/d' \"\\\$HOME/.bashrc\" > \"\\\$HOME/.bashrc.cdist-tmp\"
+sed '/rvm\\/scripts\\/rvm/d' \"\\\$HOME/.bashrc\" > \"\\\$HOME/.bashrc.cdist-tmp\"
 mv \"\\\$HOME/.bashrc.cdist-tmp\" \"\\\$HOME/.bashrc\""
 DONE
     ;;
diff --git a/cdist/conf/type/__ssh_authorized_key/gencode-remote b/cdist/conf/type/__ssh_authorized_key/gencode-remote
index 82c90d61..f37aa565 100755
--- a/cdist/conf/type/__ssh_authorized_key/gencode-remote
+++ b/cdist/conf/type/__ssh_authorized_key/gencode-remote
@@ -48,7 +48,7 @@ add_line() {
    line="$2"
    # escape single quotes
    line_sanitised=$(echo "$line" | sed -e "s/'/'\"'\"'/g")
-   printf '%s' "printf '%s\n' '$line_sanitised' >> $file"
+   printf '%s' "printf '%s\\n' '$line_sanitised' >> $file"
 }
 
 
diff --git a/cdist/conf/type/__staged_file/gencode-local b/cdist/conf/type/__staged_file/gencode-local
index 4edaba7f..e78b50bd 100755
--- a/cdist/conf/type/__staged_file/gencode-local
+++ b/cdist/conf/type/__staged_file/gencode-local
@@ -67,10 +67,10 @@ fetch_and_prepare_file() {
    # shellcheck disable=SC2016
    printf 'cd "$tmpdir"\n'
    # shellcheck disable=SC2059
-   printf "$fetch_command > \"%s\"\n" "$source" "$source_file_name"
+   printf "$fetch_command > \"%s\"\\n" "$source" "$source_file_name"
    prepare_command="$(cat "$__object/parameter/prepare-command")"
    # shellcheck disable=SC2059
-   printf "$prepare_command > \"%s\"\n" "$source_file_name" "$stage_file"
+   printf "$prepare_command > \"%s\"\\n" "$source_file_name" "$stage_file"
    printf 'cd - >/dev/null\n'
    # shellcheck disable=SC2016
    printf 'rm -rf "$tmpdir"\n'