Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
eepm
Commits
2daba332
Commit
2daba332
authored
Mar 29, 2023
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
epm-sh-functions: add sed_escape
parent
a6c0d2b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
epm-sh-functions
bin/epm-sh-functions
+15
-0
test_sed_escaping.sh
tests/test_sed_escaping.sh
+17
-0
No files found.
bin/epm-sh-functions
View file @
2daba332
...
...
@@ -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
()
...
...
tests/test_sed_escaping.sh
0 → 100755
View file @
2daba332
#!/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"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment