Dabombber
Senior Member
The _quote function used in helper.sh escapes the pipe character '|' and ignores the ampersand '&'.
Examples where this is broken, and an echo bug for good measure:
This could be fixed by changing the _quote function to
Code:
_quote() {
echo $1 | sed 's/[]\/$*.^|[]/\\&/g'
}
Examples where this is broken, and an echo bug for good measure:
Code:
#!/bin/sh
source /usr/sbin/helper.sh
TMPFILE="output.txt"
echo -e "a\nb\nc\n" > "$TMPFILE"
pc_replace "|b" "123" "$TMPFILE"
echo 'pc_replace "|b" "123" "$TMPFILE"'
cat "$TMPFILE"
echo -e "a\nb\nc\n" > "$TMPFILE"
pc_replace "b" "&123&" "$TMPFILE"
echo 'pc_replace "b" "&123&" "$TMPFILE"'
cat "$TMPFILE"
echo -e "a\nb\nc\n" > "$TMPFILE"
pc_replace "b" "-n" "$TMPFILE"
echo 'pc_replace "b" "-n" "$TMPFILE"'
cat "$TMPFILE"
rm "$TMPFILE"
Code:
$ sh test.sh
pc_replace "|b" "123" "$TMPFILE"
123a
123
123c
123
pc_replace "b" "&123&" "$TMPFILE"
a
b123b
c
pc_replace "b" "-n" "$TMPFILE"
a
c
This could be fixed by changing the _quote function to
Code:
_quote() {
printf "%s\n" "$1" | sed 's/[]\/$*.^&[]/\\&/g'
}