clarify relation between line and regex
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
fd490b39f1
commit
9e40d7bc91
2 changed files with 26 additions and 4 deletions
|
@ -20,8 +20,10 @@
|
|||
#
|
||||
|
||||
file="/$__object_id"
|
||||
regex=""
|
||||
state_should="present"
|
||||
[ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file")
|
||||
[ -f "$__object/parameter/regex" ] && regex=$(cat "$__object/parameter/regex")
|
||||
[ -f "$__object/parameter/state" ] && state_should=$(cat "$__object/parameter/state")
|
||||
|
||||
state_is="$(cat "$__object/explorer/state")"
|
||||
|
@ -41,7 +43,18 @@ case "$state_should" in
|
|||
|
||||
;;
|
||||
absent)
|
||||
echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\""
|
||||
if [ "$regex" -a "$line" ]; then
|
||||
echo "Mutally exclusive parameters regex and line given for state absent" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ "$line" ] && regex="^$line\$"
|
||||
|
||||
cat << eof
|
||||
tmp=\$(mktemp)
|
||||
sed '/$regex/d' "$file" > \$tmp && cat "\$tmp" > "$file" && rm -f "\$tmp"
|
||||
eof
|
||||
#echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\""
|
||||
;;
|
||||
*)
|
||||
echo "Unknown state: $state_should" >&2
|
||||
|
|
|
@ -23,11 +23,20 @@ state::
|
|||
|
||||
line::
|
||||
Specifies the line which should be absent or present
|
||||
|
||||
Must be present, if state is present.
|
||||
Must not be combined with regex, if state is absent.
|
||||
|
||||
regex::
|
||||
If supplied, search for this regex.
|
||||
Otherwise entire line must be matched.
|
||||
If state is present, search for this pattern and add
|
||||
given line, if the given regular expression does not match.
|
||||
|
||||
In case of absent, ensure all lines matching the
|
||||
regular expression are absent (cannot be combined with
|
||||
the line parameter, if state is absent).
|
||||
|
||||
If the regular expression contains / (slashes), they need
|
||||
to be escaped with \ (backslash): / becomes \/.
|
||||
|
||||
file::
|
||||
If supplied, use this as the destination file.
|
||||
|
|
Loading…
Reference in a new issue