Skip to content

Commit

Permalink
Update _input-output-functions.sh
Browse files Browse the repository at this point in the history
Fix the TextPrefix function:
In the prefix value escape all / by \/
otherwise sed -e "/.../.../" gets invalid syntax
see #3160 (comment)
  • Loading branch information
jsmeix committed Feb 27, 2024
1 parent 69cb322 commit 1c047d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion usr/share/rear/lib/_input-output-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,15 @@ function LogToSyslog () {
# | last line
function TextPrefix () {
{ local prefix="${1- }"
sed -e "s/^[ \t]*/$prefix/"
# In prefix escape all / by \/ (otherwise sed -e "/.../.../" gets invalid syntax)
# via ${prefix//\//\\/} bash parameter expansion (pattern substitution)
# prefix - name of the variable containing the content
# //... - replace all instances of ...
# \/ - the / character (/ escaped as \/)
# /... - replace with ...
# \\/ - the \/ characters (\ escaped as \\ plus /)
# see https://github.com/rear/rear/pull/3160#issuecomment-1966495212
sed -e "s/^[ \t]*/${prefix//\//\\/}/"
} 2>>/dev/$DISPENSABLE_OUTPUT_DEV
}

Expand Down

0 comments on commit 1c047d9

Please sign in to comment.