Skip to contentSkip to conversation

scripts/config: allow colons in option strings for sed

PATCH In review Jeremie Francois (on alpha) 3 participants 3 messages Apr 10, 2020 – Apr 12, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/config: allow colons in option strings for sed

Sed broke on some strings as it used colon as a separator. I made it more robust by using \001, which is legit POSIX AFAIK.

E.g. ./config --set-str CONFIG_USBNET_DEVADDR "de:ad:be:ef:00:01" failed with: sed: -e expression #1, char 55: unknown option to `s'

---
 scripts/config | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/config +4 -1
index e0e39826dae9..d365081b60b2 100755
@@ -7,6 +7,9 @@ myname=${0##*/}
 # If no prefix forced, use the default CONFIG_
 CONFIG_="${CONFIG_-CONFIG_}"
 
+# We use an uncommon delimiter for sed substitutions
+SED_DELIM=$(echo -en "\001")
+
 usage() {
 	cat >&2 <<EOL
 Manipulate options in a .config file from the command line.
@@ -83,7 +86,7 @@ txt_subst() {
 	local infile="$3"
 	local tmpfile="$infile.swp"
 
-	sed -e "s:$before:$after:" "$infile" >"$tmpfile"
+	sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile"
 	# replace original file with the edited one
 	mv "$tmpfile" "$infile"
 }
Signature · 1 line
2.17.1
#1 lore raw

[adding Cc's]

Quoted 35 lines · Jeremie Francois (on alpha)

Sed broke on some strings as it used colon as a separator. I made it more robust by using \001, which is legit POSIX AFAIK.

E.g. ./config --set-str CONFIG_USBNET_DEVADDR "de:ad:be:ef:00:01" failed with: sed: -e expression #1, char 55: unknown option to `s'

---
 scripts/config | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/config +4 -1
index e0e39826dae9..d365081b60b2 100755
@@ -7,6 +7,9 @@ myname=${0##*/}
 # If no prefix forced, use the default CONFIG_
 CONFIG_="${CONFIG_-CONFIG_}"
 
+# We use an uncommon delimiter for sed substitutions
+SED_DELIM=$(echo -en "\001")
+
 usage() {
 	cat >&2 <<EOL
 Manipulate options in a .config file from the command line.
@@ -83,7 +86,7 @@ txt_subst() {
 	local infile="$3"
 	local tmpfile="$infile.swp"
 
-	sed -e "s:$before:$after:" "$infile" >"$tmpfile"
+	sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile"
 	# replace original file with the edited one
 	mv "$tmpfile" "$infile"
 }
Signature · 1 line
~Randy
#2 lore raw
In reply to Jeremie Francois (on alpha)
Quoted 17 lines · Jeremie Francois (on alpha)

Sed broke on some strings as it used colon as a separator. I made it more robust by using \001, which is legit POSIX AFAIK.

E.g. ./config --set-str CONFIG_USBNET_DEVADDR "de:ad:be:ef:00:01" failed with: sed: -e expression #1, char 55: unknown option to `s'

---
 scripts/config | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/config +0 -0
index e0e39826dae9..d365081b60b2 100755

scripts/config myname=${0##*/} · line 11

Quoted 5 lines
scripts/config +2 -0
@@ -7,6 +7,9 @@ myname=${0##*/}
 # If no prefix forced, use the default CONFIG_
 CONFIG_="${CONFIG_-CONFIG_}"
 
+# We use an uncommon delimiter for sed substitutions
+SED_DELIM=$(echo -en "\001")

At first, 'echo -en' caught my eye,
but this script is always run by bash.
So, there is no portability issue here.

Applied to linux-kbuild.
Thanks.

Quoted 16 lines
scripts/config +2 -2
+
 usage() {
        cat >&2 <<EOL
 Manipulate options in a .config file from the command line.
@@ -83,7 +86,7 @@ txt_subst() {
        local infile="$3"
        local tmpfile="$infile.swp"
 
-       sed -e "s:$before:$after:" "$infile" >"$tmpfile"
+       sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile"
        # replace original file with the edited one
        mv "$tmpfile" "$infile"
 }
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada