Browse Source

fix subunsub issue

Pi 1 year ago
parent
commit
35ef8c8af3
1 changed files with 9 additions and 8 deletions
  1. 9 8
      subunsub.sh

+ 9 - 8
subunsub.sh

@@ -3,12 +3,13 @@ set -euo pipefail
 exec 4<>"${SLIST}.txt" 5>"${SLIST}.txt.new"
 exec 4<>"${SLIST}.txt" 5>"${SLIST}.txt.new"
 flock -n 4
 flock -n 4
 flock -n 5
 flock -n 5
-if [ "${1}" == "UNSUBSCRIBE" ]; then
-        grep -Fivx -e "${2}" -e "${3}" <&4 || ! grep -Fqx -e "${2}" -e "${3}"
-else
-        grep -Fix -e "${2}" -e "${3}" <&4 || cat "${SLIST}.txt" - <<EOF
-${2}
-${3}
-EOF
-fi >&5
+{
+	grep -Fivx -e "${2}" -e "${3}" <&4 || :
+	if [ "${1}" == "SUBSCRIBE" ]; then
+		cat - <<-EOF
+		${2}
+		${3}
+		EOF
+	fi
+} >&5
 mv "${SLIST}.txt.new" "${SLIST}.txt"
 mv "${SLIST}.txt.new" "${SLIST}.txt"