Skip to content

Commit

Permalink
samba.sh: fix regexp syntax (#320)
Browse files Browse the repository at this point in the history
Fix the regular expression so the line `foo = bar` gets correctly parsed into `key=foo` and `value=bar`.
  • Loading branch information
olafmandel authored and David Personette committed Jul 3, 2020
1 parent 54e2458 commit d407fa1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit d407fa1

Please sign in to comment.