From bb6ab15994e602987f14b5607ab88e2306678c01 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 8 Nov 2017 09:12:30 +0100 Subject: passwort-tresor: interprete search string as literal first --- passwort-tresor.in | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/passwort-tresor.in b/passwort-tresor.in index fd7c6ae..4611f83 100644 --- a/passwort-tresor.in +++ b/passwort-tresor.in @@ -197,13 +197,21 @@ beiFehlerBeenden 1 if ${greppw} then - for suchStr in "${suche}" "${suche}.*:\$" "^${suche}.*:\$" "^${suche}:\$" "" - do - [ $(grep -c "${suchStr}" "${tmpDir}/output") -eq 1 ] && break + count=0 + for subst in 's/[.[]/\\\0/g' ''; do + sucheSubst=$( + echo "${suche}" | \ + sed "${subst}" + ) + for suchStr in "${sucheSubst}" "${sucheSubst}.*:\$" "^${sucheSubst}.*:\$" "^${sucheSubst}:\$" + do + count=$(grep -c "${suchStr}" "${tmpDir}/output") + [ "${count}" -eq 1 ] && break + done done - if [ -z "${suchStr}" ] + if [ "${count}" -ne 1 ] then - >&2 echo "'${suche}' ist nicht genau ein Mal vorhanden!" + >&2 printf '"%s" ist nicht genau ein Mal vorhanden!\n' "${suche}" beenden 1 fi output="$(grep -2 "${suchStr}" "${tmpDir}/output" | tail -n2)" -- cgit v1.2.3