diff options
author | Erich Eckner <git@eckner.net> | 2017-11-08 09:12:30 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-11-08 09:12:30 +0100 |
commit | bb6ab15994e602987f14b5607ab88e2306678c01 (patch) | |
tree | 0cc5f1828e4a860c12655441d843d38f51bbf18a | |
parent | ce66273990b81aa82553eefba681bf881934d814 (diff) | |
download | passwort-tresor-bb6ab15994e602987f14b5607ab88e2306678c01.tar.xz |
passwort-tresor: interprete search string as literal first
-rw-r--r-- | passwort-tresor.in | 18 |
1 files 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)" |