Commit 2daba332 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm-sh-functions: add sed_escape

parent a6c0d2b3
......@@ -265,6 +265,16 @@ strip_spaces()
echo "$*" | filter_strip_spaces
}
# https://superuser.com/questions/422459/substitution-in-text-file-without-regular-expressions
# http://stackoverflow.com/a/2705678/120999
# use for subst complex string with symbols treating as regexp
sed_escape()
{
echo "$*" | sed -e 's/[]()$*.^|[]/\\&/g'
}
# param true false
subst_option()
{
......@@ -799,6 +809,11 @@ realpath()
}
fi
# TODO: use perl if sed -i is not accessible
# sed -i is only supported in GNU sed.
# sed -i "s/$find/$replace/g" "$@"
# perl -p -i -e "s/$find/$replace/g" "$@"
# add subst if missed
if ! which subst 2>/dev/null >/dev/null ; then
subst()
......
#!/bin/sh
load_helper()
{
. ../bin/$1
}
PMTYPE=apt-rpm
. ../bin/epm-sh-functions
test()
{
[ "$(sed_escape "$1")" = "$2" ] && echo "OK: $1 -> $2" || echo "FAILED: $1 -> $(sed_escape "$1"), waited $2"
}
test "rpm [lab50] http://packages.lab50.net okular/alt/x86_64 p10" "rpm \[lab50\] http://packages\.lab50\.net okular/alt/x86_64 p10"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment