Skip to contentSkip to conversation

support/scripts/mkusers: fix double comma in group member list

PATCH New William Sherrer 1 participant 1 message Nov 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 support/scripts/mkusers: fix double comma in group member list

When add_user_to_group() updates an existing user, it removes the current entry from the list and appends the user to the end. If the user was in the middle of a list (e.g. "user1,user2,user3,user4"), remove "user3" leaves a double command (e.g. "user1,user2,,user4,user3").

The cleanup regex s/,+/, matches on the first comma but fails to collapse subsequent ones since it lacks the global flag.

This commit adds the g flag so consectutive commas are collapsed.

---
 support/scripts/mkusers | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
support/scripts/mkusers +1 -1
index 87a36a89a1..581df86f3e 100755
@@ -300,7 +300,7 @@ add_user_to_group() {
         sed -r -i --follow-symlinks \
                   -e 's/^('"${group}"':.*:)(([^:]+,)?)'"${username}"'(,[^:]+*)?$/\1\2\4/;'  \
                   -e 's/^('"${group}"':.*)$/\1,'"${username}"'/;'                           \
-                  -e 's/,+/,/'                                                              \
+                  -e 's/,+/,/g'                                                             \
                   -e 's/:,/:/'                                                              \
                   "${_f}"
     done
Signature · 6 lines
2.43.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot