diff --git a/cdist/conf/type/__key_value/gencode-remote b/cdist/conf/type/__key_value/gencode-remote
index 5fa24d5b..c1a6bca8 100755
--- a/cdist/conf/type/__key_value/gencode-remote
+++ b/cdist/conf/type/__key_value/gencode-remote
@@ -46,7 +46,8 @@ case "$state_should" in
             ;;
             wrongvalue)
                 # change exisiting value
-                echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\""
+                printf 'sed "s|^%s\(%s\+\).*|%s\\1%s|" "%s" > "%s.cdist-tmp"\n' \
+                    "$key" "$delimiter" "$key" "$value" "$file" "$file"
                 echo "mv \"$file.cdist-tmp\" \"$file\""
             ;;
             *)