From d407fa1b6220f2821ddf848ab346d65a93a535d9 Mon Sep 17 00:00:00 2001 From: Olaf Mandel Date: Fri, 3 Jul 2020 14:55:38 +0200 Subject: [PATCH] samba.sh: fix regexp syntax (#320) Fix the regular expression so the line `foo = bar` gets correctly parsed into `key=foo` and `value=bar`. --- samba.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samba.sh b/samba.sh index 14304f1..ebb4e20 100755 --- a/samba.sh +++ b/samba.sh @@ -39,7 +39,7 @@ charmap() { local chars="$1" file=/etc/samba/smb.conf # option) raw option # Return: line added to smb.conf (replaces existing line with same key) generic() { local section="$1" key="$(sed 's| *=.*||' <<< $2)" \ - value="$(sed 's|.*= *||' <<< $2)" file=/etc/samba/smb.conf + value="$(sed 's|[^=]*= *||' <<< $2)" file=/etc/samba/smb.conf if sed -n '/^\['"$section"'\]/,/^\[/p' $file | grep -qE '^;*\s*'"$key"; then sed -i '/^\['"$1"'\]/,/^\[/s|^;*\s*\('"$key"' = \).*| \1'"$value"'|' \ "$file" @@ -52,8 +52,8 @@ generic() { local section="$1" key="$(sed 's| *=.*||' <<< $2)" \ # Arguments: # option) raw option # Return: line added to smb.conf (replaces existing line with same key) -global() { local key="$(sed 's|\([^=]*\) += .*|\1|' <<< $1)" \ - value="$(sed 's|[^=]* += +||' <<< $1)" file=/etc/samba/smb.conf +global() { local key="$(sed 's| *=.*||' <<< $1)" \ + value="$(sed 's|[^=]*= *||' <<< $1)" file=/etc/samba/smb.conf if sed -n '/^\[global\]/,/^\[/p' $file | grep -qE '^;*\s*'"$key"; then sed -i '/^\[global\]/,/^\[/s|^;*\s*\('"$key"' = \).*| \1'"$value"'|' \ "$file"